commandkit 1.2.0-rc.11 → 1.2.0-rc.12
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-DKnFVDME.d.ts → ActionRow-B-7n9MMr.d.ts} +3 -3
- package/dist/{ActionRow-CbdGFWMT.js → ActionRow-uJxU4UGo.js} +2 -2
- package/dist/ActionRow-uJxU4UGo.js.map +1 -0
- package/dist/{Button-4ZUXdA56.d.ts → Button-RMp-w8HV.d.ts} +4 -4
- package/dist/{ButtonKit-C7r7RPNf.d.ts → ButtonKit-9k4yfhYD.d.ts} +2 -2
- package/dist/{ChannelSelectMenuKit-BrXvBYNH.d.ts → ChannelSelectMenuKit-CsYgIyKe.d.ts} +3 -3
- package/dist/{CommandKitEventsChannel-BtRzr3Tz.js → CommandKitEventsChannel-2l9Za-le.js} +1 -1
- package/dist/{CommandKitEventsChannel-BtRzr3Tz.js.map → CommandKitEventsChannel-2l9Za-le.js.map} +1 -1
- package/dist/{CommandsRouter-CoOA7hkf.d.ts → CommandsRouter-CBdsqaWK.d.ts} +1 -1
- package/dist/{CommandsRouter-Dmzw-ikm.js → CommandsRouter-CWMipIis.js} +1 -1
- package/dist/{CommandsRouter-Dmzw-ikm.js.map → CommandsRouter-CWMipIis.js.map} +1 -1
- package/dist/{CompilerPlugin-M8r3yNAl.js → CompilerPlugin-CZ4412Zm.js} +2 -2
- package/dist/{CompilerPlugin-M8r3yNAl.js.map → CompilerPlugin-CZ4412Zm.js.map} +1 -1
- package/dist/{DefaultLogger-XCOl5nLd.d.ts → DefaultLogger-CHMVsizQ.d.ts} +2 -2
- package/dist/{EventInterceptor-CQEXyUTp.js → EventInterceptor-BWoEJMHZ.js} +1 -1
- package/dist/{EventInterceptor-CQEXyUTp.js.map → EventInterceptor-BWoEJMHZ.js.map} +1 -1
- package/dist/{EventWorkerContext-XNgriym3.d.ts → EventWorkerContext-CLhZRHhH.d.ts} +3 -3
- package/dist/{EventWorkerContext-Dq29tieI.js → EventWorkerContext-D_9q1Bm2.js} +1 -1
- package/dist/EventWorkerContext-D_9q1Bm2.js.map +1 -0
- package/dist/{EventsRouter-BacqK6z3.d.ts → EventsRouter-4pT6vj-U.d.ts} +1 -1
- package/dist/{EventsRouter-3Gygh-km.js → EventsRouter-C04XqRKf.js} +1 -1
- package/dist/{EventsRouter-3Gygh-km.js.map → EventsRouter-C04XqRKf.js.map} +1 -1
- package/dist/{ILogger-BW8GM-YZ.d.ts → ILogger-BQ2ew4zR.d.ts} +1 -1
- package/dist/{Logger-DyfkPk7u.d.ts → Logger-DyV7oli4.d.ts} +2 -2
- package/dist/{MentionableSelectMenuKit-CPTKqx-O.d.ts → MentionableSelectMenuKit-CO9phWMf.d.ts} +3 -3
- package/dist/{MessageCommandParser-Dl0xxtdr.js → MessageCommandParser-CKh-tM97.js} +52 -53
- package/dist/{MessageCommandParser-Dl0xxtdr.js.map → MessageCommandParser-CKh-tM97.js.map} +1 -1
- package/dist/{MessageCommandParser-BsGMOTDo.d.ts → MessageCommandParser-DEOl_ifb.d.ts} +1 -1
- package/dist/{Modal-C6UTRdYQ.d.ts → Modal-Calb46SJ.d.ts} +11 -8
- package/dist/{ModalKit-Btz58KYn.d.ts → ModalKit-Cq2ns6jv.d.ts} +2 -2
- package/dist/{PluginCommon-Cvl5yYM_.js → PluginCommon-CPWV5xuX.js} +1 -1
- package/dist/{PluginCommon-Cvl5yYM_.js.map → PluginCommon-CPWV5xuX.js.map} +1 -1
- package/dist/{RoleSelectMenuKit-C26lU3sN.d.ts → RoleSelectMenuKit-DvBxzpWh.d.ts} +3 -3
- package/dist/{RuntimePlugin-BUecuBIU.js → RuntimePlugin-COeXe8rP.js} +2 -2
- package/dist/{RuntimePlugin-BUecuBIU.js.map → RuntimePlugin-COeXe8rP.js.map} +1 -1
- package/dist/{SelectMenu-Diy87_ba.d.ts → SelectMenu-VcDhOGoJ.d.ts} +8 -8
- package/dist/{StringSelectMenuKit-Bhs8U6WI.d.ts → StringSelectMenuKit-CJ0MzUZJ.d.ts} +3 -3
- package/dist/{UserSelectMenuKit-CfqFJdxz.d.ts → UserSelectMenuKit-C_J-9RJs.d.ts} +3 -3
- package/dist/analytics/analytics-engine.d.ts +31 -29
- package/dist/analytics/analytics-engine.js +37 -34
- package/dist/analytics/analytics-provider.d.ts +31 -29
- package/dist/analytics/constants.js +1 -1
- package/dist/analytics/utils.js +37 -34
- package/dist/{analytics-engine-AaAl3kQM.d.ts → analytics-engine-NOInIjv8.d.ts} +28 -6
- package/dist/app/commands/AppCommandRunner.d.ts +31 -29
- package/dist/app/commands/AppCommandRunner.js +37 -34
- package/dist/app/commands/Context.d.ts +31 -29
- package/dist/app/commands/Context.js +37 -34
- package/dist/app/commands/MessageCommandParser.d.ts +1 -1
- package/dist/app/commands/MessageCommandParser.js +1 -1
- package/dist/app/commands/helpers.d.ts +1 -1
- package/dist/app/commands/helpers.js +1 -1
- package/dist/app/events/EventWorkerContext.d.ts +32 -30
- package/dist/app/events/EventWorkerContext.js +1 -1
- package/dist/app/handlers/AppCommandHandler.d.ts +31 -29
- package/dist/app/handlers/AppCommandHandler.js +37 -34
- package/dist/app/handlers/AppEventsHandler.d.ts +31 -29
- package/dist/app/handlers/AppEventsHandler.js +37 -34
- package/dist/app/index.d.ts +31 -29
- package/dist/app/index.js +38 -35
- package/dist/app/interrupt/signals.d.ts +1 -1
- package/dist/app/interrupt/signals.js +2 -2
- package/dist/app/middlewares/permissions.d.ts +31 -29
- package/dist/app/middlewares/permissions.js +37 -34
- package/dist/app/register/CommandRegistrar.d.ts +31 -29
- package/dist/app/register/CommandRegistrar.js +37 -34
- package/dist/app/router/CommandsRouter.d.ts +1 -1
- package/dist/app/router/CommandsRouter.js +1 -1
- package/dist/app/router/EventsRouter.d.ts +1 -1
- package/dist/app/router/EventsRouter.js +1 -1
- package/dist/app/router/index.d.ts +3 -3
- package/dist/app/router/index.js +3 -3
- package/dist/{app-process-cj2vF12T.js → app-process-AQ3Cbf6j.js} +4 -4
- package/dist/app-process-AQ3Cbf6j.js.map +1 -0
- package/dist/{build-B5qTswWF.js → build-BYMHMOl_.js} +11 -12
- package/dist/{build-B5qTswWF.js.map → build-BYMHMOl_.js.map} +1 -1
- package/dist/cli/app-process.js +5 -5
- package/dist/cli/build.d.ts +31 -29
- package/dist/cli/build.js +40 -37
- package/dist/cli/common.d.ts +31 -29
- package/dist/cli/common.js +3 -3
- package/dist/cli/development.js +41 -38
- package/dist/cli/development.js.map +1 -1
- package/dist/cli/env.js +1 -1
- package/dist/cli/generators.js +3 -3
- package/dist/cli/information.js +2 -2
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +38 -35
- package/dist/cli/production.js +43 -41
- package/dist/cli/production.js.map +1 -1
- package/dist/cli/type-checker.js +4 -4
- package/dist/cli/utils.js +1 -1
- package/dist/{commandkit-ZoBBh0Q_.js → commandkit-DabqpQ6v.js} +100 -58
- package/dist/commandkit-DabqpQ6v.js.map +1 -0
- package/dist/commandkit.d.ts +31 -29
- package/dist/commandkit.js +37 -34
- package/dist/{common-vnMIelAE.js → common-CCx-FJI4.js} +3 -3
- package/dist/common-CCx-FJI4.js.map +1 -0
- package/dist/{common-DOCvOVC4.d.ts → common-DHTTnX82.d.ts} +2 -2
- package/dist/{common-CrqwC-sx.js → common-fIO6fqGZ.js} +4 -5
- package/dist/{common-CrqwC-sx.js.map → common-fIO6fqGZ.js.map} +1 -1
- package/dist/components/common/EventInterceptor.js +1 -1
- package/dist/components/common/element.d.ts +3 -3
- package/dist/components/common/element.js +1 -1
- package/dist/components/common/types.js +1 -1
- package/dist/components/{v2 → display}/common.d.ts +1 -1
- package/dist/components/display/common.js +3 -0
- package/dist/components/display/container.d.ts +2 -0
- package/dist/components/display/container.js +4 -0
- package/dist/components/display/file.d.ts +2 -0
- package/dist/components/display/file.js +3 -0
- package/dist/components/display/index.d.ts +10 -0
- package/dist/components/display/index.js +23 -0
- package/dist/components/display/label.d.ts +2 -0
- package/dist/components/display/label.js +4 -0
- package/dist/components/{v2 → display}/media-gallery.d.ts +1 -1
- package/dist/components/{v2 → display}/media-gallery.js +2 -2
- package/dist/components/display/poll.d.ts +2 -0
- package/dist/components/display/poll.js +5 -0
- package/dist/components/display/section.d.ts +2 -0
- package/dist/components/display/section.js +5 -0
- package/dist/components/display/separator.d.ts +2 -0
- package/dist/components/display/separator.js +3 -0
- package/dist/components/display/text-display.d.ts +2 -0
- package/dist/components/display/text-display.js +3 -0
- package/dist/components/index.d.ts +25 -23
- package/dist/components/index.js +41 -35
- package/dist/components/interactive/action-row/ActionRow.d.ts +6 -0
- package/dist/components/interactive/action-row/ActionRow.js +3 -0
- package/dist/components/interactive/button/Button.d.ts +7 -0
- package/dist/components/interactive/button/Button.js +41 -0
- package/dist/components/{v1 → interactive}/button/ButtonKit.d.ts +1 -1
- package/dist/components/interactive/button/ButtonKit.js +41 -0
- package/dist/components/{v1 → interactive}/modal/Modal.d.ts +4 -4
- package/dist/components/interactive/modal/Modal.js +44 -0
- package/dist/components/{v1 → interactive}/modal/ModalKit.d.ts +1 -1
- package/dist/components/interactive/modal/ModalKit.js +41 -0
- package/dist/components/{v1 → interactive}/select-menu/ChannelSelectMenuKit.d.ts +2 -2
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.js +41 -0
- package/dist/components/{v1 → interactive}/select-menu/MentionableSelectMenuKit.d.ts +2 -2
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.js +41 -0
- package/dist/components/{v1 → interactive}/select-menu/RoleSelectMenuKit.d.ts +2 -2
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.js +41 -0
- package/dist/components/{v1 → interactive}/select-menu/SelectMenu.d.ts +7 -7
- package/dist/components/interactive/select-menu/SelectMenu.js +46 -0
- package/dist/components/{v1 → interactive}/select-menu/StringSelectMenuKit.d.ts +2 -2
- package/dist/components/interactive/select-menu/StringSelectMenuKit.js +41 -0
- package/dist/components/{v1 → interactive}/select-menu/UserSelectMenuKit.d.ts +2 -2
- package/dist/components/interactive/select-menu/UserSelectMenuKit.js +41 -0
- package/dist/components/{v1 → interactive}/select-menu/common.d.ts +1 -1
- package/dist/components/interactive/select-menu/common.js +1 -0
- package/dist/config/config.d.ts +32 -30
- package/dist/config/config.js +37 -34
- package/dist/config/default.d.ts +31 -29
- package/dist/config/default.js +37 -34
- package/dist/config/loader.d.ts +31 -29
- package/dist/config/loader.js +37 -34
- package/dist/config/types.d.ts +31 -29
- package/dist/config/utils.d.ts +31 -29
- package/dist/config/utils.js +1 -1
- package/dist/{config-D-JMp2IO.d.ts → config-DbgXt6mf.d.ts} +2 -2
- package/dist/{constants-4oxxvaJA.js → constants-AH-9qJ89.js} +1 -1
- package/dist/{constants-4oxxvaJA.js.map → constants-AH-9qJ89.js.map} +1 -1
- package/dist/{constants-B5_Ta7PR.js → constants-BMWH2YUr.js} +1 -1
- package/dist/{constants-B5_Ta7PR.js.map → constants-BMWH2YUr.js.map} +1 -1
- package/dist/{constants-D8PMA9on.d.ts → constants-CCFSX2NG.d.ts} +1 -1
- package/dist/{constants-BOOGN85p.js → constants-D0dawKxO.js} +1 -1
- package/dist/{constants-BOOGN85p.js.map → constants-D0dawKxO.js.map} +1 -1
- package/dist/{constants-MKu-Q1jh.d.ts → constants-DqnSDZ6l.d.ts} +1 -1
- package/dist/{container-DHBELeJ3.d.ts → container-1ltvkavy.d.ts} +2 -2
- package/dist/{container-C6GtfAPW.js → container-DC0eQigs.js} +3 -3
- package/dist/container-DC0eQigs.js.map +1 -0
- package/dist/context/async-context.d.ts +31 -29
- package/dist/context/async-context.js +37 -34
- package/dist/context/environment.d.ts +31 -29
- package/dist/context/environment.js +37 -34
- package/dist/{dotprops-tnhpnszJ.js → dotprops-DvJUE8fw.js} +1 -1
- package/dist/{dotprops-tnhpnszJ.js.map → dotprops-DvJUE8fw.js.map} +1 -1
- package/dist/{element-CAXu1XtK.d.ts → element-CvNhvLZ8.d.ts} +3 -3
- package/dist/{element-Bak9llw_.js → element-DibzzA5L.js} +1 -1
- package/dist/element-DibzzA5L.js.map +1 -0
- package/dist/{env-_68PRRoA.js → env-8yY-6pbC.js} +1 -1
- package/dist/{env-_68PRRoA.js.map → env-8yY-6pbC.js.map} +1 -1
- package/dist/{error-codes-B4TyW4Ct.d.ts → error-codes-BiNRVMiV.d.ts} +1 -1
- package/dist/events/CommandKitEventsChannel.d.ts +31 -29
- package/dist/events/CommandKitEventsChannel.js +1 -1
- package/dist/{feature-flags-CKNrjgqg.js → feature-flags-BoBV4Dsj.js} +4 -4
- package/dist/feature-flags-BoBV4Dsj.js.map +1 -0
- package/dist/{file-DVOELoNv.js → file-DAUOZYhC.js} +2 -2
- package/dist/file-DAUOZYhC.js.map +1 -0
- package/dist/{file-DTrr-p09.d.ts → file-n2yl_-vl.d.ts} +2 -2
- package/dist/flags/FlagProvider.d.ts +31 -29
- package/dist/flags/feature-flags.d.ts +31 -29
- package/dist/flags/feature-flags.js +38 -35
- package/dist/flags/store.d.ts +31 -29
- package/dist/flags/store.js +1 -1
- package/dist/{helpers-Dl8wW6aO.js → helpers-D2_1jih6.js} +1 -1
- package/dist/{helpers-Dl8wW6aO.js.map → helpers-D2_1jih6.js.map} +1 -1
- package/dist/{helpers-Wg6P5fRQ.d.ts → helpers-hDh_tMb6.d.ts} +1 -1
- package/dist/index.d.ts +42 -40
- package/dist/index.js +46 -39
- package/dist/index.js.map +1 -1
- package/dist/{init-_7_QDifv.js → init-CBb0StSB.js} +11 -15
- package/dist/{init-_7_QDifv.js.map → init-CBb0StSB.js.map} +1 -1
- package/dist/{init-DOr-Y3GQ.d.ts → init-DSYckXwx.d.ts} +1 -1
- package/dist/kv/constants.d.ts +1 -1
- package/dist/kv/constants.js +1 -1
- package/dist/kv/dotprops.js +1 -1
- package/dist/kv/kv.d.ts +2 -2
- package/dist/kv/kv.js +5 -7
- package/dist/kv/kv.js.map +1 -1
- package/dist/kv/serde.d.ts +2 -2
- package/dist/kv/serde.js +2 -2
- package/dist/label-D-uJWRZ0.js +36 -0
- package/dist/label-D-uJWRZ0.js.map +1 -0
- package/dist/label-D0KXeBhk.d.ts +29 -0
- package/dist/logger/DefaultLogger.d.ts +2 -2
- package/dist/logger/DefaultLogger.js +37 -34
- package/dist/logger/ILogger.d.ts +1 -1
- package/dist/logger/ILogger.js +1 -1
- package/dist/logger/Logger.d.ts +2 -2
- package/dist/logger/Logger.js +37 -34
- package/dist/logger/NoopLogger.d.ts +1 -1
- package/dist/{media-gallery-zDtJ3kxb.js → media-gallery-BLhwe5lO.js} +3 -3
- package/dist/media-gallery-BLhwe5lO.js.map +1 -0
- package/dist/{media-gallery-BMsXSot3.d.ts → media-gallery-BzG70ued.d.ts} +2 -2
- package/dist/plugins/CompilerPlugin.d.ts +31 -29
- package/dist/plugins/CompilerPlugin.js +2 -2
- package/dist/plugins/PluginCommon.d.ts +31 -29
- package/dist/plugins/PluginCommon.js +1 -1
- package/dist/plugins/RuntimePlugin.d.ts +31 -29
- package/dist/plugins/RuntimePlugin.js +2 -2
- package/dist/plugins/index.d.ts +31 -29
- package/dist/plugins/index.js +37 -34
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +31 -29
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +37 -34
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +31 -29
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +37 -34
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +31 -29
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +37 -34
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +31 -29
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +37 -34
- package/dist/plugins/plugin-runtime/runtime.d.ts +31 -29
- package/dist/plugins/plugin-runtime/runtime.js +1 -1
- package/dist/plugins/types.d.ts +31 -29
- package/dist/plugins/types.js +1 -1
- package/dist/poll-Bc6rjeUS.js +101 -0
- package/dist/poll-Bc6rjeUS.js.map +1 -0
- package/dist/poll-HnaJcB0o.d.ts +89 -0
- package/dist/{resolve-file-url-ChIyw-Vf.js → resolve-file-url-CJoD0FAn.js} +1 -1
- package/dist/{resolve-file-url-ChIyw-Vf.js.map → resolve-file-url-CJoD0FAn.js.map} +1 -1
- package/dist/{resolve-file-url-yO8bUxok.d.ts → resolve-file-url-DFtR8jRR.d.ts} +1 -1
- package/dist/{section-DlvrDoJK.js → section-BMcHN97i.js} +3 -3
- package/dist/section-BMcHN97i.js.map +1 -0
- package/dist/{section-Dh_FhPeC.d.ts → section-BOaJKXiy.d.ts} +2 -2
- package/dist/{separator-DL6QH5H1.js → separator-C___2K-f.js} +2 -2
- package/dist/separator-C___2K-f.js.map +1 -0
- package/dist/{separator-CMf6Cyy5.d.ts → separator-Cb7-6T6N.d.ts} +2 -2
- package/dist/{serde-BYaKrsOV.d.ts → serde-D4H23l2F.d.ts} +2 -2
- package/dist/{serde-Cc8iUa9J.js → serde-DHHwhltz.js} +2 -2
- package/dist/{serde-Cc8iUa9J.js.map → serde-DHHwhltz.js.map} +1 -1
- package/dist/{signals-ChFMD7mB.js → signals-Cnqe9dFV.js} +2 -2
- package/dist/{signals-ChFMD7mB.js.map → signals-Cnqe9dFV.js.map} +1 -1
- package/dist/{signals-SHg7J1U_.d.ts → signals-DBS60vTo.d.ts} +1 -1
- package/dist/{store-CM6pWVZh.js → store-ZwL2gN6a.js} +1 -1
- package/dist/{store-CM6pWVZh.js.map → store-ZwL2gN6a.js.map} +1 -1
- package/dist/{text-display-DRw3r_lK.d.ts → text-display-B_hpz50P.d.ts} +2 -2
- package/dist/{text-display-DbMumig_.js → text-display-BtQR88kY.js} +2 -2
- package/dist/text-display-BtQR88kY.js.map +1 -0
- package/dist/{type-checker-ocNSZh0W.js → type-checker-CEFHoQoV.js} +2 -2
- package/dist/{type-checker-ocNSZh0W.js.map → type-checker-CEFHoQoV.js.map} +1 -1
- package/dist/{types-package-BWArjyBF.js → types-package-D11rQXLs.js} +3 -4
- package/dist/{types-package-BWArjyBF.js.map → types-package-D11rQXLs.js.map} +1 -1
- package/dist/types.d.ts +31 -29
- package/dist/{utilities-DtdPlr4c.d.ts → utilities-CQUaua43.d.ts} +1 -1
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/dev-hooks.d.ts +31 -29
- package/dist/utils/dev-hooks.js +37 -34
- package/dist/utils/error-codes.d.ts +1 -1
- package/dist/utils/resolve-file-url.d.ts +1 -1
- package/dist/utils/resolve-file-url.js +1 -1
- package/dist/utils/types-package.js +2 -2
- package/dist/utils/useful-stuff/async-queue.js +1 -2
- package/dist/utils/useful-stuff/async-queue.js.map +1 -1
- package/dist/utils/useful-stuff/ratelimiter.js +1 -2
- package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
- package/dist/utils/useful-stuff/semaphore.js +1 -3
- package/dist/utils/useful-stuff/semaphore.js.map +1 -1
- package/dist/utils/utilities.d.ts +1 -1
- package/dist/utils/utilities.js +37 -34
- package/dist/utils/{warn-unstable.d.ts → warning.d.ts} +12 -3
- package/dist/utils/warning.js +5 -0
- package/dist/{utils-DCSnVAZ6.js → utils-Bf-3Eevb.js} +1 -1
- package/dist/{utils-DCSnVAZ6.js.map → utils-Bf-3Eevb.js.map} +1 -1
- package/dist/{utils-KsNof0Xz.js → utils-Br3eenD1.js} +1 -1
- package/dist/{utils-KsNof0Xz.js.map → utils-Br3eenD1.js.map} +1 -1
- package/dist/{version--Q1nmlBz.js → version-DC4j2ZwU.js} +2 -2
- package/dist/{version--Q1nmlBz.js.map → version-DC4j2ZwU.js.map} +1 -1
- package/dist/{version-CtJtBJXI.d.ts → version-DggMfP_1.d.ts} +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/warning-CszH8HeS.js +53 -0
- package/dist/warning-CszH8HeS.js.map +1 -0
- package/package.json +3 -3
- package/dist/ActionRow-CbdGFWMT.js.map +0 -1
- package/dist/EventWorkerContext-Dq29tieI.js.map +0 -1
- package/dist/app-process-cj2vF12T.js.map +0 -1
- package/dist/commandkit-ZoBBh0Q_.js.map +0 -1
- package/dist/common-vnMIelAE.js.map +0 -1
- package/dist/components/v1/action-row/ActionRow.d.ts +0 -6
- package/dist/components/v1/action-row/ActionRow.js +0 -3
- package/dist/components/v1/button/Button.d.ts +0 -7
- package/dist/components/v1/button/Button.js +0 -38
- package/dist/components/v1/button/ButtonKit.js +0 -38
- package/dist/components/v1/modal/Modal.js +0 -41
- package/dist/components/v1/modal/ModalKit.js +0 -38
- package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +0 -38
- package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +0 -38
- package/dist/components/v1/select-menu/RoleSelectMenuKit.js +0 -38
- package/dist/components/v1/select-menu/SelectMenu.js +0 -43
- package/dist/components/v1/select-menu/StringSelectMenuKit.js +0 -38
- package/dist/components/v1/select-menu/UserSelectMenuKit.js +0 -38
- package/dist/components/v1/select-menu/common.js +0 -1
- package/dist/components/v2/common.js +0 -3
- package/dist/components/v2/container.d.ts +0 -2
- package/dist/components/v2/container.js +0 -4
- package/dist/components/v2/file.d.ts +0 -2
- package/dist/components/v2/file.js +0 -3
- package/dist/components/v2/index.d.ts +0 -8
- package/dist/components/v2/index.js +0 -17
- package/dist/components/v2/section.d.ts +0 -2
- package/dist/components/v2/section.js +0 -5
- package/dist/components/v2/separator.d.ts +0 -2
- package/dist/components/v2/separator.js +0 -3
- package/dist/components/v2/text-display.d.ts +0 -2
- package/dist/components/v2/text-display.js +0 -3
- package/dist/container-C6GtfAPW.js.map +0 -1
- package/dist/element-Bak9llw_.js.map +0 -1
- package/dist/feature-flags-CKNrjgqg.js.map +0 -1
- package/dist/file-DVOELoNv.js.map +0 -1
- package/dist/media-gallery-zDtJ3kxb.js.map +0 -1
- package/dist/section-DlvrDoJK.js.map +0 -1
- package/dist/separator-DL6QH5H1.js.map +0 -1
- package/dist/text-display-DbMumig_.js.map +0 -1
- package/dist/utils/warn-unstable.js +0 -26
- package/dist/utils/warn-unstable.js.map +0 -1
- /package/dist/{ILogger-dQ7Y9X1f.js → ILogger-B0q7p7L1.js} +0 -0
- /package/dist/{app-HN1cVg8J.js → app-CrjK9yWX.js} +0 -0
- /package/dist/{common-CcfjYnPG.js → common-0Iw8ZeM6.js} +0 -0
- /package/dist/{router-Dn35v30f.js → display-WDb9wMCv.js} +0 -0
- /package/dist/{index-CUPkUUOR.d.ts → index-B5F3AfVc.d.ts} +0 -0
- /package/dist/{index-Dw5cCt-A.d.ts → index-BLwMeReG.d.ts} +0 -0
- /package/dist/{index-E7Wvm5uX.d.ts → index-h64gcVNJ.d.ts} +0 -0
- /package/dist/{runtime-DB9CiPfe.js → router-BvamdzoF.js} +0 -0
- /package/dist/{types-CUZOquUl.js → runtime-Skt5NiOc.js} +0 -0
- /package/dist/{types-q0Nm882H.js → types-Cdh4uaFR.js} +0 -0
- /package/dist/{v2-DofkPKHs.js → types-TC4g3w91.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-queue.js","names":[],"sources":["../../../src/utils/useful-stuff/async-queue.ts"],"sourcesContent":["/**\n * Async queue implementation for processing tasks sequentially or with limited concurrency.\n * Useful for rate-limiting, batching, or controlling resource usage.\n */\n\nexport interface AsyncQueueOptions {\n /** Maximum number of concurrent tasks. Default: 1 (sequential) */\n concurrency?: number;\n /** Optional callback invoked when all tasks are completed */\n onDrain?: () => void | Promise<void>;\n /** Optional AbortSignal for cancelling the queue */\n signal?: AbortSignal;\n}\n\nexport type AsyncQueueTask<T> = () => Promise<T>;\n\nexport class AsyncQueue {\n private readonly concurrency: number;\n private readonly onDrain?: () => void | Promise<void>;\n private readonly signal?: AbortSignal;\n private running = 0;\n private paused = false;\n private aborted = false;\n private queue: Array<() => void> = [];\n\n constructor(options: AsyncQueueOptions = {}) {\n this.concurrency = options.concurrency ?? 1;\n this.onDrain = options.onDrain;\n this.signal = options.signal;\n\n if (this.signal) {\n this.signal.addEventListener('abort', () => {\n this.abort();\n });\n }\n }\n\n /**\n * Adds a task to the queue.\n * @param task - The async function to execute.\n * @param signal - Optional AbortSignal for cancelling this specific task.\n * @returns Promise resolving to the result of the task.\n */\n public add<T>(task: AsyncQueueTask<T>, signal?: AbortSignal): Promise<T> {\n if (this.aborted) {\n return Promise.reject(new Error('Queue has been aborted'));\n }\n\n return new Promise<T>((resolve, reject) => {\n const run = async () => {\n if (this.paused || this.aborted) {\n if (this.aborted) {\n reject(new Error('Queue has been aborted'));\n } else {\n this.queue.push(run);\n }\n return;\n }\n\n // Check if task-specific signal is aborted\n if (signal?.aborted) {\n reject(new Error('Task was aborted'));\n return;\n }\n\n this.running++;\n try {\n const result = await task();\n resolve(result);\n } catch (err) {\n reject(err);\n } finally {\n this.running--;\n this.next();\n }\n };\n\n if (this.running < this.concurrency && !this.paused && !this.aborted) {\n run();\n } else {\n this.queue.push(run);\n }\n });\n }\n\n /**\n * Pauses the queue. No new tasks will be started until resumed.\n */\n public pause() {\n this.paused = true;\n }\n\n /**\n * Resumes the queue and processes pending tasks.\n */\n public resume() {\n if (!this.paused) return;\n this.paused = false;\n this.next();\n }\n\n /**\n * Aborts the queue, rejecting all pending tasks.\n */\n public abort() {\n this.aborted = true;\n this.clear();\n }\n\n /**\n * Clears all pending tasks from the queue.\n */\n public clear() {\n this.queue = [];\n }\n\n /**\n * Returns the number of running tasks.\n */\n public getRunning(): number {\n return this.running;\n }\n\n /**\n * Returns the number of pending tasks in the queue.\n */\n public getPending(): number {\n return this.queue.length;\n }\n\n /**\n * Returns true if the queue is currently paused.\n */\n public isPaused(): boolean {\n return this.paused;\n }\n\n /**\n * Returns true if the queue has been aborted.\n */\n public isAborted(): boolean {\n return this.aborted;\n }\n\n private next() {\n if (this.paused || this.aborted) return;\n while (this.running < this.concurrency && this.queue.length > 0) {\n const fn = this.queue.shift();\n if (fn) fn();\n }\n if (this.running === 0 && this.queue.length === 0 && this.onDrain) {\n this.onDrain();\n }\n }\n}\n\n/**\n * Creates a new async queue instance with the specified configuration.\n * @param options - Configuration options for the async queue.\n * @returns New AsyncQueue instance.\n *\n * @example\n * ```typescript\n * const controller = new AbortController();\n * const queue = createAsyncQueue({\n * concurrency: 2,\n * signal: controller.signal\n * });\n * queue.add(async () => await doSomething());\n * controller.abort(); // Aborts the queue\n * ```\n */\nexport function createAsyncQueue(options?: AsyncQueueOptions): AsyncQueue {\n return new AsyncQueue(options);\n}\n"],"mappings":";;AAgBA,IAAa,aAAb,MAAwB;CACtB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,UAAU;CAClB,AAAQ,SAAS;CACjB,AAAQ,UAAU;CAClB,AAAQ,QAA2B,EAAE;CAErC,YAAY,UAA6B,EAAE,EAAE;AAC3C,OAAK,cAAc,QAAQ,eAAe;AAC1C,OAAK,UAAU,QAAQ;AACvB,OAAK,SAAS,QAAQ;AAEtB,MAAI,KAAK,OACP,MAAK,OAAO,iBAAiB,eAAe;AAC1C,QAAK,OAAO;IACZ;;;;;;;;CAUN,AAAO,IAAO,MAAyB,QAAkC;AACvE,MAAI,KAAK,QACP,QAAO,QAAQ,uBAAO,IAAI,MAAM,yBAAyB,CAAC;AAG5D,SAAO,IAAI,SAAY,SAAS,WAAW;GACzC,MAAM,MAAM,YAAY;AACtB,QAAI,KAAK,UAAU,KAAK,SAAS;AAC/B,SAAI,KAAK,QACP,wBAAO,IAAI,MAAM,yBAAyB,CAAC;SAE3C,MAAK,MAAM,KAAK,IAAI;AAEtB;;AAIF,wDAAI,OAAQ,SAAS;AACnB,4BAAO,IAAI,MAAM,mBAAmB,CAAC;AACrC;;AAGF,SAAK;AACL,QAAI;
|
|
1
|
+
{"version":3,"file":"async-queue.js","names":[],"sources":["../../../src/utils/useful-stuff/async-queue.ts"],"sourcesContent":["/**\n * Async queue implementation for processing tasks sequentially or with limited concurrency.\n * Useful for rate-limiting, batching, or controlling resource usage.\n */\n\nexport interface AsyncQueueOptions {\n /** Maximum number of concurrent tasks. Default: 1 (sequential) */\n concurrency?: number;\n /** Optional callback invoked when all tasks are completed */\n onDrain?: () => void | Promise<void>;\n /** Optional AbortSignal for cancelling the queue */\n signal?: AbortSignal;\n}\n\nexport type AsyncQueueTask<T> = () => Promise<T>;\n\nexport class AsyncQueue {\n private readonly concurrency: number;\n private readonly onDrain?: () => void | Promise<void>;\n private readonly signal?: AbortSignal;\n private running = 0;\n private paused = false;\n private aborted = false;\n private queue: Array<() => void> = [];\n\n constructor(options: AsyncQueueOptions = {}) {\n this.concurrency = options.concurrency ?? 1;\n this.onDrain = options.onDrain;\n this.signal = options.signal;\n\n if (this.signal) {\n this.signal.addEventListener('abort', () => {\n this.abort();\n });\n }\n }\n\n /**\n * Adds a task to the queue.\n * @param task - The async function to execute.\n * @param signal - Optional AbortSignal for cancelling this specific task.\n * @returns Promise resolving to the result of the task.\n */\n public add<T>(task: AsyncQueueTask<T>, signal?: AbortSignal): Promise<T> {\n if (this.aborted) {\n return Promise.reject(new Error('Queue has been aborted'));\n }\n\n return new Promise<T>((resolve, reject) => {\n const run = async () => {\n if (this.paused || this.aborted) {\n if (this.aborted) {\n reject(new Error('Queue has been aborted'));\n } else {\n this.queue.push(run);\n }\n return;\n }\n\n // Check if task-specific signal is aborted\n if (signal?.aborted) {\n reject(new Error('Task was aborted'));\n return;\n }\n\n this.running++;\n try {\n const result = await task();\n resolve(result);\n } catch (err) {\n reject(err);\n } finally {\n this.running--;\n this.next();\n }\n };\n\n if (this.running < this.concurrency && !this.paused && !this.aborted) {\n run();\n } else {\n this.queue.push(run);\n }\n });\n }\n\n /**\n * Pauses the queue. No new tasks will be started until resumed.\n */\n public pause() {\n this.paused = true;\n }\n\n /**\n * Resumes the queue and processes pending tasks.\n */\n public resume() {\n if (!this.paused) return;\n this.paused = false;\n this.next();\n }\n\n /**\n * Aborts the queue, rejecting all pending tasks.\n */\n public abort() {\n this.aborted = true;\n this.clear();\n }\n\n /**\n * Clears all pending tasks from the queue.\n */\n public clear() {\n this.queue = [];\n }\n\n /**\n * Returns the number of running tasks.\n */\n public getRunning(): number {\n return this.running;\n }\n\n /**\n * Returns the number of pending tasks in the queue.\n */\n public getPending(): number {\n return this.queue.length;\n }\n\n /**\n * Returns true if the queue is currently paused.\n */\n public isPaused(): boolean {\n return this.paused;\n }\n\n /**\n * Returns true if the queue has been aborted.\n */\n public isAborted(): boolean {\n return this.aborted;\n }\n\n private next() {\n if (this.paused || this.aborted) return;\n while (this.running < this.concurrency && this.queue.length > 0) {\n const fn = this.queue.shift();\n if (fn) fn();\n }\n if (this.running === 0 && this.queue.length === 0 && this.onDrain) {\n this.onDrain();\n }\n }\n}\n\n/**\n * Creates a new async queue instance with the specified configuration.\n * @param options - Configuration options for the async queue.\n * @returns New AsyncQueue instance.\n *\n * @example\n * ```typescript\n * const controller = new AbortController();\n * const queue = createAsyncQueue({\n * concurrency: 2,\n * signal: controller.signal\n * });\n * queue.add(async () => await doSomething());\n * controller.abort(); // Aborts the queue\n * ```\n */\nexport function createAsyncQueue(options?: AsyncQueueOptions): AsyncQueue {\n return new AsyncQueue(options);\n}\n"],"mappings":";;AAgBA,IAAa,aAAb,MAAwB;CACtB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,UAAU;CAClB,AAAQ,SAAS;CACjB,AAAQ,UAAU;CAClB,AAAQ,QAA2B,EAAE;CAErC,YAAY,UAA6B,EAAE,EAAE;AAC3C,OAAK,cAAc,QAAQ,eAAe;AAC1C,OAAK,UAAU,QAAQ;AACvB,OAAK,SAAS,QAAQ;AAEtB,MAAI,KAAK,OACP,MAAK,OAAO,iBAAiB,eAAe;AAC1C,QAAK,OAAO;IACZ;;;;;;;;CAUN,AAAO,IAAO,MAAyB,QAAkC;AACvE,MAAI,KAAK,QACP,QAAO,QAAQ,uBAAO,IAAI,MAAM,yBAAyB,CAAC;AAG5D,SAAO,IAAI,SAAY,SAAS,WAAW;GACzC,MAAM,MAAM,YAAY;AACtB,QAAI,KAAK,UAAU,KAAK,SAAS;AAC/B,SAAI,KAAK,QACP,wBAAO,IAAI,MA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|
-
|
|
85
|
-
if (now - lastReset > this.resetInterval) {
|
|
84
|
+
if (now - (this.lastReset.get(key) || 0) > this.resetInterval) {
|
|
86
85
|
await this.storage.delete(key);
|
|
87
86
|
this.lastReset.set(key, now);
|
|
88
87
|
this.limits.set(key, 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ratelimiter.js","names":[],"sources":["../../../src/utils/useful-stuff/ratelimiter.ts"],"sourcesContent":["/**\n * Default timeout interval for rate limiting in milliseconds\n */\nexport const DEFAULT_TIMEOUT = 60000;\n\n/**\n * Default maximum number of requests allowed per interval\n */\nexport const DEFAULT_MAX_REQUESTS = 10;\n\n/**\n * Interface for rate limit storage implementations.\n * Provides methods to store, retrieve, and delete rate limit data.\n */\nexport interface RateLimitStorage {\n /**\n * Retrieves the current request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the current request count\n */\n get(key: string): Promise<number>;\n\n /**\n * Sets the request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @param value - The request count to store\n * @returns Promise that resolves when the value is stored\n */\n set(key: string, value: number): Promise<void>;\n\n /**\n * Deletes the rate limit entry for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the entry is deleted\n */\n delete(key: string): Promise<void>;\n}\n\n/**\n * Configuration options for rate limiting\n */\nexport interface RateLimitOptions {\n /** Maximum number of requests allowed per interval. Default: 10 */\n maxRequests?: number;\n /** Time interval in milliseconds for the rate limit window. Default: 60000 */\n interval?: number;\n /** Storage implementation for persisting rate limit data. Default: {@link MemoryRateLimitStorage} */\n storage?: RateLimitStorage;\n}\n\n/**\n * In-memory storage implementation for rate limiting.\n * Suitable for single-instance applications.\n */\nexport class MemoryRateLimitStorage implements RateLimitStorage {\n private readonly store = new Map<string, number>();\n\n /**\n * Retrieves the current request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the current request count or 0 if not found\n */\n async get(key: string): Promise<number> {\n return this.store.get(key) || 0;\n }\n\n /**\n * Sets the request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @param value - The request count to store\n * @returns Promise that resolves immediately\n */\n async set(key: string, value: number): Promise<void> {\n this.store.set(key, value);\n }\n\n /**\n * Deletes the rate limit entry for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves immediately\n */\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n}\n\n/**\n * Rate limiter implementation that enforces request limits per key.\n * Supports configurable request limits and time intervals.\n */\nexport class RateLimiter {\n private readonly limits: Map<string, number> = new Map();\n private readonly lastReset: Map<string, number> = new Map();\n private readonly resetInterval: number;\n\n /**\n * Creates a new rate limiter instance\n * @param maxRequests - Maximum number of requests allowed per interval (default: 10)\n * @param interval - Time interval in milliseconds for the rate limit window (default: 60000)\n * @param storage - Optional storage implementation (default: MemoryRateLimitStorage)\n */\n public constructor(\n private readonly maxRequests: number = DEFAULT_MAX_REQUESTS,\n private readonly interval: number = DEFAULT_TIMEOUT,\n private storage: RateLimitStorage = new MemoryRateLimitStorage(),\n ) {\n this.resetInterval = interval;\n }\n\n /**\n * Sets the storage implementation for the rate limiter\n * @param storage - The storage implementation to use\n */\n public setStorage(storage: RateLimitStorage) {\n this.storage = storage;\n }\n\n /**\n * Gets the storage implementation for the rate limiter\n * @returns The storage implementation\n */\n public getStorage(): RateLimitStorage {\n return this.storage;\n }\n\n /**\n * Checks if a request is allowed for the given key and increments the counter if allowed\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to true if the request is allowed, false if rate limited\n */\n public async limit(key: string): Promise<boolean> {\n const now = Date.now();\n const lastReset = this.lastReset.get(key) || 0;\n const timeSinceReset = now - lastReset;\n\n // Reset counter if interval has passed\n if (timeSinceReset > this.resetInterval) {\n await this.storage.delete(key);\n this.lastReset.set(key, now);\n this.limits.set(key, 0);\n }\n\n // Get current count from storage\n const currentCount = await this.storage.get(key);\n\n // Check if limit exceeded\n if (currentCount >= this.maxRequests) {\n return false;\n }\n\n // Increment counter\n const newCount = currentCount + 1;\n await this.storage.set(key, newCount);\n this.limits.set(key, newCount);\n\n return true;\n }\n\n /**\n * Gets the remaining requests allowed for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the number of remaining requests\n */\n public async getRemaining(key: string): Promise<number> {\n const currentCount = await this.storage.get(key);\n return Math.max(0, this.maxRequests - currentCount);\n }\n\n /**\n * Gets the time until the rate limit resets for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the time in milliseconds until reset, or 0 if no limit is active\n */\n public async getResetTime(key: string): Promise<number> {\n const lastReset = this.lastReset.get(key) || 0;\n const now = Date.now();\n const timeSinceReset = now - lastReset;\n\n if (timeSinceReset >= this.resetInterval) {\n return 0;\n }\n\n return this.resetInterval - timeSinceReset;\n }\n\n /**\n * Resets the rate limit for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the reset is complete\n */\n public async reset(key: string): Promise<void> {\n await this.storage.delete(key);\n this.limits.delete(key);\n this.lastReset.delete(key);\n }\n\n /**\n * Gets the current configuration of the rate limiter\n * @returns Object containing the current maxRequests and interval values\n */\n public getConfig(): Omit<RateLimitOptions, 'storage'> {\n return {\n maxRequests: this.maxRequests,\n interval: this.interval,\n };\n }\n}\n\n/**\n * Default rate limiter instance for global use\n */\nexport const defaultRateLimiter = new RateLimiter();\n\n/**\n * Convenience function to check if a request is allowed for a given key.\n * Uses the default rate limiter instance.\n *\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to true if the request is allowed, false if rate limited\n *\n * @example\n * ```typescript\n * const allowed = await ratelimit('user:123');\n * // update the default rate limiter config\n * import { defaultRateLimiter } from 'commandkit/ratelimit';\n *\n * // update max allowed requests\n * defaultRateLimiter.setMaxRequests(10);\n *\n * // update the timeout interval\n * defaultRateLimiter.setInterval(30000);\n *\n * // update the storage implementation\n * defaultRateLimiter.setStorage(new RedisStorage());\n * ```\n */\nexport async function ratelimit(key: string): Promise<boolean> {\n return defaultRateLimiter.limit(key);\n}\n\n/**\n * Creates a new rate limiter instance with the specified configuration\n * @param options - Configuration options for the rate limiter\n * @returns New RateLimiter instance\n *\n * @example\n * ```typescript\n * const limiter = createRateLimiter({\n * maxRequests: 5,\n * interval: 30000,\n * storage: new CustomStorage()\n * });\n * ```\n */\nexport function createRateLimiter(options: RateLimitOptions): RateLimiter {\n return new RateLimiter(\n options.maxRequests,\n options.interval,\n options.storage,\n );\n}\n\n/**\n * Gets the remaining requests for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the number of remaining requests\n */\nexport async function getRemainingRequests(key: string): Promise<number> {\n return defaultRateLimiter.getRemaining(key);\n}\n\n/**\n * Gets the reset time for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the time in milliseconds until reset\n */\nexport async function getResetTime(key: string): Promise<number> {\n return defaultRateLimiter.getResetTime(key);\n}\n\n/**\n * Resets the rate limit for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the reset is complete\n */\nexport async function resetRateLimit(key: string): Promise<void> {\n return defaultRateLimiter.reset(key);\n}\n"],"mappings":";;;;;AAGA,MAAa,kBAAkB;;;;AAK/B,MAAa,uBAAuB;;;;;AA8CpC,IAAa,yBAAb,MAAgE;CAC9D,AAAiB,wBAAQ,IAAI,KAAqB;;;;;;CAOlD,MAAM,IAAI,KAA8B;AACtC,SAAO,KAAK,MAAM,IAAI,IAAI,IAAI;;;;;;;;CAShC,MAAM,IAAI,KAAa,OAA8B;AACnD,OAAK,MAAM,IAAI,KAAK,MAAM;;;;;;;CAQ5B,MAAM,OAAO,KAA4B;AACvC,OAAK,MAAM,OAAO,IAAI;;;;;;;AAQ1B,IAAa,cAAb,MAAyB;CACvB,AAAiB,yBAA8B,IAAI,KAAK;CACxD,AAAiB,4BAAiC,IAAI,KAAK;CAC3D,AAAiB;;;;;;;CAQjB,AAAO,YACP,AAAiB,cAAsB,sBACvC,AAAiB,WAAmB,i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;;;;;AAyBnD,eAAsB,UAAU,KAA+B;AAC7D,QAAO,mBAAmB,MAAM,IAAI;;;;;;;;;;;;;;;;AAiBtC,SAAgB,kBAAkB,SAAwC;AACxE,QAAO,IAAI,YACT,QAAQ,aACR,QAAQ,UACR,QAAQ,QACT;;;;;;;AAQH,eAAsB,qBAAqB,KAA8B;AACvE,QAAO,mBAAmB,aAAa,IAAI;;;;;;;AAQ7C,eAAsB,aAAa,KAA8B;AAC/D,QAAO,mBAAmB,aAAa,IAAI;;;;;;;AAQ7C,eAAsB,eAAe,KAA4B;AAC/D,QAAO,mBAAmB,MAAM,IAAI"}
|
|
1
|
+
{"version":3,"file":"ratelimiter.js","names":[],"sources":["../../../src/utils/useful-stuff/ratelimiter.ts"],"sourcesContent":["/**\n * Default timeout interval for rate limiting in milliseconds\n */\nexport const DEFAULT_TIMEOUT = 60000;\n\n/**\n * Default maximum number of requests allowed per interval\n */\nexport const DEFAULT_MAX_REQUESTS = 10;\n\n/**\n * Interface for rate limit storage implementations.\n * Provides methods to store, retrieve, and delete rate limit data.\n */\nexport interface RateLimitStorage {\n /**\n * Retrieves the current request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the current request count\n */\n get(key: string): Promise<number>;\n\n /**\n * Sets the request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @param value - The request count to store\n * @returns Promise that resolves when the value is stored\n */\n set(key: string, value: number): Promise<void>;\n\n /**\n * Deletes the rate limit entry for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the entry is deleted\n */\n delete(key: string): Promise<void>;\n}\n\n/**\n * Configuration options for rate limiting\n */\nexport interface RateLimitOptions {\n /** Maximum number of requests allowed per interval. Default: 10 */\n maxRequests?: number;\n /** Time interval in milliseconds for the rate limit window. Default: 60000 */\n interval?: number;\n /** Storage implementation for persisting rate limit data. Default: {@link MemoryRateLimitStorage} */\n storage?: RateLimitStorage;\n}\n\n/**\n * In-memory storage implementation for rate limiting.\n * Suitable for single-instance applications.\n */\nexport class MemoryRateLimitStorage implements RateLimitStorage {\n private readonly store = new Map<string, number>();\n\n /**\n * Retrieves the current request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the current request count or 0 if not found\n */\n async get(key: string): Promise<number> {\n return this.store.get(key) || 0;\n }\n\n /**\n * Sets the request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @param value - The request count to store\n * @returns Promise that resolves immediately\n */\n async set(key: string, value: number): Promise<void> {\n this.store.set(key, value);\n }\n\n /**\n * Deletes the rate limit entry for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves immediately\n */\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n}\n\n/**\n * Rate limiter implementation that enforces request limits per key.\n * Supports configurable request limits and time intervals.\n */\nexport class RateLimiter {\n private readonly limits: Map<string, number> = new Map();\n private readonly lastReset: Map<string, number> = new Map();\n private readonly resetInterval: number;\n\n /**\n * Creates a new rate limiter instance\n * @param maxRequests - Maximum number of requests allowed per interval (default: 10)\n * @param interval - Time interval in milliseconds for the rate limit window (default: 60000)\n * @param storage - Optional storage implementation (default: MemoryRateLimitStorage)\n */\n public constructor(\n private readonly maxRequests: number = DEFAULT_MAX_REQUESTS,\n private readonly interval: number = DEFAULT_TIMEOUT,\n private storage: RateLimitStorage = new MemoryRateLimitStorage(),\n ) {\n this.resetInterval = interval;\n }\n\n /**\n * Sets the storage implementation for the rate limiter\n * @param storage - The storage implementation to use\n */\n public setStorage(storage: RateLimitStorage) {\n this.storage = storage;\n }\n\n /**\n * Gets the storage implementation for the rate limiter\n * @returns The storage implementation\n */\n public getStorage(): RateLimitStorage {\n return this.storage;\n }\n\n /**\n * Checks if a request is allowed for the given key and increments the counter if allowed\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to true if the request is allowed, false if rate limited\n */\n public async limit(key: string): Promise<boolean> {\n const now = Date.now();\n const lastReset = this.lastReset.get(key) || 0;\n const timeSinceReset = now - lastReset;\n\n // Reset counter if interval has passed\n if (timeSinceReset > this.resetInterval) {\n await this.storage.delete(key);\n this.lastReset.set(key, now);\n this.limits.set(key, 0);\n }\n\n // Get current count from storage\n const currentCount = await this.storage.get(key);\n\n // Check if limit exceeded\n if (currentCount >= this.maxRequests) {\n return false;\n }\n\n // Increment counter\n const newCount = currentCount + 1;\n await this.storage.set(key, newCount);\n this.limits.set(key, newCount);\n\n return true;\n }\n\n /**\n * Gets the remaining requests allowed for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the number of remaining requests\n */\n public async getRemaining(key: string): Promise<number> {\n const currentCount = await this.storage.get(key);\n return Math.max(0, this.maxRequests - currentCount);\n }\n\n /**\n * Gets the time until the rate limit resets for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the time in milliseconds until reset, or 0 if no limit is active\n */\n public async getResetTime(key: string): Promise<number> {\n const lastReset = this.lastReset.get(key) || 0;\n const now = Date.now();\n const timeSinceReset = now - lastReset;\n\n if (timeSinceReset >= this.resetInterval) {\n return 0;\n }\n\n return this.resetInterval - timeSinceReset;\n }\n\n /**\n * Resets the rate limit for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the reset is complete\n */\n public async reset(key: string): Promise<void> {\n await this.storage.delete(key);\n this.limits.delete(key);\n this.lastReset.delete(key);\n }\n\n /**\n * Gets the current configuration of the rate limiter\n * @returns Object containing the current maxRequests and interval values\n */\n public getConfig(): Omit<RateLimitOptions, 'storage'> {\n return {\n maxRequests: this.maxRequests,\n interval: this.interval,\n };\n }\n}\n\n/**\n * Default rate limiter instance for global use\n */\nexport const defaultRateLimiter = new RateLimiter();\n\n/**\n * Convenience function to check if a request is allowed for a given key.\n * Uses the default rate limiter instance.\n *\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to true if the request is allowed, false if rate limited\n *\n * @example\n * ```typescript\n * const allowed = await ratelimit('user:123');\n * // update the default rate limiter config\n * import { defaultRateLimiter } from 'commandkit/ratelimit';\n *\n * // update max allowed requests\n * defaultRateLimiter.setMaxRequests(10);\n *\n * // update the timeout interval\n * defaultRateLimiter.setInterval(30000);\n *\n * // update the storage implementation\n * defaultRateLimiter.setStorage(new RedisStorage());\n * ```\n */\nexport async function ratelimit(key: string): Promise<boolean> {\n return defaultRateLimiter.limit(key);\n}\n\n/**\n * Creates a new rate limiter instance with the specified configuration\n * @param options - Configuration options for the rate limiter\n * @returns New RateLimiter instance\n *\n * @example\n * ```typescript\n * const limiter = createRateLimiter({\n * maxRequests: 5,\n * interval: 30000,\n * storage: new CustomStorage()\n * });\n * ```\n */\nexport function createRateLimiter(options: RateLimitOptions): RateLimiter {\n return new RateLimiter(\n options.maxRequests,\n options.interval,\n options.storage,\n );\n}\n\n/**\n * Gets the remaining requests for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the number of remaining requests\n */\nexport async function getRemainingRequests(key: string): Promise<number> {\n return defaultRateLimiter.getRemaining(key);\n}\n\n/**\n * Gets the reset time for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the time in milliseconds until reset\n */\nexport async function getResetTime(key: string): Promise<number> {\n return defaultRateLimiter.getResetTime(key);\n}\n\n/**\n * Resets the rate limit for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the reset is complete\n */\nexport async function resetRateLimit(key: string): Promise<void> {\n return defaultRateLimiter.reset(key);\n}\n"],"mappings":";;;;;AAGA,MAAa,kBAAkB;;;;AAK/B,MAAa,uBAAuB;;;;;AA8CpC,IAAa,yBAAb,MAAgE;CAC9D,AAAiB,wBAAQ,IAAI,KAAqB;;;;;;CAOlD,MAAM,IAAI,KAA8B;AACtC,SAAO,KAAK,MAAM,IAAI,IAAI,IAAI;;;;;;;;CAShC,MAAM,IAAI,KAAa,OAA8B;AACnD,OAAK,MAAM,IAAI,KAAK,MAAM;;;;;;;CAQ5B,MAAM,OAAO,KAA4B;AACvC,OAAK,MAA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IAAI;AACvB,OAAK,UAAU,OAAO,IAAI;;;;;;CAO5B,AAAO,YAA+C;AACpD,SAAO;GACL,aAAa,KAAK;GAClB,UAAU,KAAK;GAChB;;;;;;AAOL,MAAa,qBAAqB,IAAI,aAAa;;;;;;;;;;;;;;;;;;;;;;;;AAyBnD,eAAsB,UAAU,KAA+B;AAC7D,QAAO,mBAAmB,MAAM,IAAI;;;;;;;;;;;;;;;;AAiBtC,SAAgB,kBAAkB,SAAwC;AACxE,QAAO,IAAI,YACT,QAAQ,aACR,QAAQ,UACR,QAAQ,QACT;;;;;;;AAQH,eAAsB,qBAAqB,KAA8B;AACvE,QAAO,mBAAmB,aAAa,IAAI;;;;;;;AAQ7C,eAAsB,aAAa,KAA8B;AAC/D,QAAO,mBAAmB,aAAa,IAAI;;;;;;;AAQ7C,eAAsB,eAAe,KAA4B;AAC/D,QAAO,mBAAmB,MAAM,IAAI"}
|
|
@@ -142,9 +142,7 @@ var Semaphore = class {
|
|
|
142
142
|
* @returns Promise resolving to the number of acquired permits
|
|
143
143
|
*/
|
|
144
144
|
async getAcquiredPermits(key) {
|
|
145
|
-
|
|
146
|
-
const available = await this.getAvailablePermits(key);
|
|
147
|
-
return total - available;
|
|
145
|
+
return await this.getTotalPermits(key) - await this.getAvailablePermits(key);
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
150
148
|
* Executes a function with a permit from the semaphore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semaphore.js","names":[],"sources":["../../../src/utils/useful-stuff/semaphore.ts"],"sourcesContent":["/**\n * Async semaphore implementation for controlling access to a limited pool of resources.\n * Allows a specified number of concurrent operations while blocking additional requests.\n */\n\n/**\n * Interface for semaphore storage implementations.\n * Provides methods to store, retrieve, and manage semaphore permit data.\n */\nexport interface SemaphoreStorage {\n /**\n * Attempts to acquire a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout or no permits available\n */\n acquire(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<boolean>;\n\n /**\n * Releases a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\n release(key: string): Promise<void>;\n\n /**\n * Gets the number of available permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\n getAvailablePermits(key: string): Promise<number>;\n\n /**\n * Gets the total number of permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the total number of permits\n */\n getTotalPermits(key: string): Promise<number>;\n}\n\n/**\n * Configuration options for semaphore\n */\nexport interface SemaphoreOptions {\n /** Maximum number of concurrent permits allowed. Default: 1 */\n permits?: number;\n /** Default timeout in milliseconds for permit acquisition. Default: 30000 */\n timeout?: number;\n /** Storage implementation for persisting semaphore data. Default: {@link MemorySemaphoreStorage} */\n storage?: SemaphoreStorage;\n}\n\n/**\n * In-memory storage implementation for semaphore permits.\n * Suitable for single-instance applications.\n */\nexport class MemorySemaphoreStorage implements SemaphoreStorage {\n private readonly semaphores = new Map<\n string,\n { total: number; available: number }\n >();\n\n /**\n * Attempts to acquire a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout or no permits available\n */\n async acquire(\n key: string,\n timeout: number = 30000,\n signal?: AbortSignal,\n ): Promise<boolean> {\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n // Check if aborted\n if (signal?.aborted) {\n throw new Error('Permit acquisition was aborted');\n }\n\n const semaphore = this.semaphores.get(key);\n if (semaphore && semaphore.available > 0) {\n semaphore.available--;\n return true;\n }\n await this.delay(10);\n }\n\n return false;\n }\n\n /**\n * Releases a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\n async release(key: string): Promise<void> {\n const semaphore = this.semaphores.get(key);\n if (semaphore && semaphore.available < semaphore.total) {\n semaphore.available++;\n }\n }\n\n /**\n * Gets the number of available permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\n async getAvailablePermits(key: string): Promise<number> {\n const semaphore = this.semaphores.get(key);\n return semaphore ? semaphore.available : 0;\n }\n\n /**\n * Gets the total number of permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the total number of permits\n */\n async getTotalPermits(key: string): Promise<number> {\n const semaphore = this.semaphores.get(key);\n return semaphore ? semaphore.total : 0;\n }\n\n /**\n * Initializes a semaphore with the specified number of permits\n * @param key - The unique identifier for the semaphore\n * @param permits - The total number of permits to allocate\n */\n initialize(key: string, permits: number): void {\n this.semaphores.set(key, { total: permits, available: permits });\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n\n/**\n * Async semaphore implementation that controls access to a limited pool of resources.\n * Allows a specified number of concurrent operations while blocking additional requests.\n */\nexport class Semaphore {\n private storage: SemaphoreStorage;\n private readonly defaultPermits: number;\n private readonly defaultTimeout: number;\n\n /**\n * Creates a new semaphore instance\n * @param options - Configuration options for the semaphore\n */\n public constructor(options: SemaphoreOptions = {}) {\n this.storage = options.storage || new MemorySemaphoreStorage();\n this.defaultPermits = options.permits || 1;\n this.defaultTimeout = options.timeout || 30000;\n }\n\n /**\n * Sets the storage implementation for the semaphore\n * @param storage - The storage implementation to use\n */\n public setStorage(storage: SemaphoreStorage) {\n this.storage = storage;\n }\n\n /**\n * Gets the storage implementation for the semaphore\n * @returns The storage implementation\n */\n public getStorage(): SemaphoreStorage {\n return this.storage;\n }\n\n /**\n * Acquires a permit for the given key\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout\n */\n public async acquire(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<boolean> {\n // Initialize semaphore if it doesn't exist\n if (this.storage instanceof MemorySemaphoreStorage) {\n const totalPermits = await this.storage.getTotalPermits(key);\n if (totalPermits === 0) {\n (this.storage as MemorySemaphoreStorage).initialize(\n key,\n this.defaultPermits,\n );\n }\n }\n\n return this.storage.acquire(key, timeout || this.defaultTimeout, signal);\n }\n\n /**\n * Releases a permit for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\n public async release(key: string): Promise<void> {\n return this.storage.release(key);\n }\n\n /**\n * Gets the number of available permits for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\n public async getAvailablePermits(key: string): Promise<number> {\n return this.storage.getAvailablePermits(key);\n }\n\n /**\n * Gets the total number of permits for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the total number of permits\n */\n public async getTotalPermits(key: string): Promise<number> {\n return this.storage.getTotalPermits(key);\n }\n\n /**\n * Gets the number of acquired permits for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of acquired permits\n */\n public async getAcquiredPermits(key: string): Promise<number> {\n const total = await this.getTotalPermits(key);\n const available = await this.getAvailablePermits(key);\n return total - available;\n }\n\n /**\n * Executes a function with a permit from the semaphore\n * @param key - The unique identifier for the semaphore\n * @param fn - The function to execute with a permit\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the permit acquisition\n * @returns Promise resolving to the result of the function execution\n * @throws Error if permit acquisition fails or function execution fails\n */\n public async withPermit<T>(\n key: string,\n fn: () => Promise<T> | T,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<T> {\n const acquired = await this.acquire(key, timeout, signal);\n if (!acquired) {\n throw new Error(`Failed to acquire permit for key: ${key}`);\n }\n\n try {\n return await fn();\n } finally {\n await this.release(key);\n }\n }\n\n /**\n * Gets the current configuration of the semaphore\n * @returns Object containing the current permits and timeout values\n */\n public getConfig(): Omit<SemaphoreOptions, 'storage'> {\n return {\n permits: this.defaultPermits,\n timeout: this.defaultTimeout,\n };\n }\n}\n\n/**\n * Default semaphore instance for global use\n */\nexport const defaultSemaphore = new Semaphore();\n\n/**\n * Convenience function to execute a function with a permit using the default semaphore.\n *\n * @param key - The unique identifier for the semaphore\n * @param fn - The function to execute with a permit\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the permit acquisition\n * @returns Promise resolving to the result of the function execution\n *\n * @example\n * ```typescript\n * const controller = new AbortController();\n * const result = await withPermit('database-connection', async () => {\n * // This code runs with a permit from the semaphore\n * return await executeDatabaseQuery();\n * }, 30000, controller.signal);\n * controller.abort(); // Cancels the permit acquisition\n * ```\n */\nexport async function withPermit<T>(\n key: string,\n fn: () => Promise<T> | T,\n timeout?: number,\n signal?: AbortSignal,\n): Promise<T> {\n return defaultSemaphore.withPermit(key, fn, timeout, signal);\n}\n\n/**\n * Creates a new semaphore instance with the specified configuration\n * @param options - Configuration options for the semaphore\n * @returns New Semaphore instance\n *\n * @example\n * ```typescript\n * const semaphore = createSemaphore({\n * permits: 5,\n * timeout: 60000,\n * storage: new RedisSemaphoreStorage()\n * });\n * ```\n */\nexport function createSemaphore(options: SemaphoreOptions): Semaphore {\n return new Semaphore(options);\n}\n\n/**\n * Acquires a permit using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout\n */\nexport async function acquirePermit(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n): Promise<boolean> {\n return defaultSemaphore.acquire(key, timeout, signal);\n}\n\n/**\n * Releases a permit using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\nexport async function releasePermit(key: string): Promise<void> {\n return defaultSemaphore.release(key);\n}\n\n/**\n * Gets the number of available permits using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\nexport async function getAvailablePermits(key: string): Promise<number> {\n return defaultSemaphore.getAvailablePermits(key);\n}\n\n/**\n * Gets the number of acquired permits using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of acquired permits\n */\nexport async function getAcquiredPermits(key: string): Promise<number> {\n return defaultSemaphore.getAcquiredPermits(key);\n}\n"],"mappings":";;;;;;AA6DA,IAAa,yBAAb,MAAgE;CAC9D,AAAiB,6BAAa,IAAI,KAGjC;;;;;;;;CASD,MAAM,QACN,KACA,UAAkB,KAClB,QACmB;EACjB,MAAM,YAAY,KAAK,KAAK;AAE5B,SAAO,KAAK,KAAK,GAAG,YAAY,SAAS;AAEvC,uDAAI,OAAQ,QACV,OAAM,IAAI,MAAM,iCAAiC;GAGnD,MAAM,YAAY,KAAK,WAAW,IAAI,IAAI;AAC1C,OAAI,aAAa,UAAU,YAAY,GAAG;AACxC,cAAU;AACV,WAAO;;AAET,SAAM,KAAK,MAAM,GAAG;;AAGtB,SAAO;;;;;;;CAQT,MAAM,QAAQ,KAA4B;EACxC,MAAM,YAAY,KAAK,WAAW,IAAI,IAAI;AAC1C,MAAI,aAAa,UAAU,YAAY,UAAU,MAC/C,WAAU;;;;;;;CASd,MAAM,oBAAoB,KAA8B;EACtD,MAAM,YAAY,KAAK,WAAW,IAAI,IAAI;AAC1C,SAAO,YAAY,UAAU,YAAY;;;;;;;CAQ3C,MAAM,gBAAgB,KAA8B;EAClD,MAAM,YAAY,KAAK,WAAW,IAAI,IAAI;AAC1C,SAAO,YAAY,UAAU,QAAQ;;;;;;;CAQvC,WAAW,KAAa,SAAuB;AAC7C,OAAK,WAAW,IAAI,KAAK;GAAE,OAAO;GAAS,WAAW;GAAS,CAAC;;CAGlE,AAAQ,MAAM,IAA2B;AACvC,SAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;;;;;;;AAQ5D,IAAa,YAAb,MAAuB;CACrB,AAAQ;CACR,AA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;;;;;;;;;AAqB/C,eAAsB,WACtB,KACA,IACA,SACA,QACa;AACX,QAAO,iBAAiB,WAAW,KAAK,IAAI,SAAS,OAAO;;;;;;;;;;;;;;;;AAiB9D,SAAgB,gBAAgB,SAAsC;AACpE,QAAO,IAAI,UAAU,QAAQ;;;;;;;;;AAU/B,eAAsB,cACtB,KACA,SACA,QACmB;AACjB,QAAO,iBAAiB,QAAQ,KAAK,SAAS,OAAO;;;;;;;AAQvD,eAAsB,cAAc,KAA4B;AAC9D,QAAO,iBAAiB,QAAQ,IAAI;;;;;;;AAQtC,eAAsB,oBAAoB,KAA8B;AACtE,QAAO,iBAAiB,oBAAoB,IAAI;;;;;;;AAQlD,eAAsB,mBAAmB,KAA8B;AACrE,QAAO,iBAAiB,mBAAmB,IAAI"}
|
|
1
|
+
{"version":3,"file":"semaphore.js","names":[],"sources":["../../../src/utils/useful-stuff/semaphore.ts"],"sourcesContent":["/**\n * Async semaphore implementation for controlling access to a limited pool of resources.\n * Allows a specified number of concurrent operations while blocking additional requests.\n */\n\n/**\n * Interface for semaphore storage implementations.\n * Provides methods to store, retrieve, and manage semaphore permit data.\n */\nexport interface SemaphoreStorage {\n /**\n * Attempts to acquire a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout or no permits available\n */\n acquire(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<boolean>;\n\n /**\n * Releases a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\n release(key: string): Promise<void>;\n\n /**\n * Gets the number of available permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\n getAvailablePermits(key: string): Promise<number>;\n\n /**\n * Gets the total number of permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the total number of permits\n */\n getTotalPermits(key: string): Promise<number>;\n}\n\n/**\n * Configuration options for semaphore\n */\nexport interface SemaphoreOptions {\n /** Maximum number of concurrent permits allowed. Default: 1 */\n permits?: number;\n /** Default timeout in milliseconds for permit acquisition. Default: 30000 */\n timeout?: number;\n /** Storage implementation for persisting semaphore data. Default: {@link MemorySemaphoreStorage} */\n storage?: SemaphoreStorage;\n}\n\n/**\n * In-memory storage implementation for semaphore permits.\n * Suitable for single-instance applications.\n */\nexport class MemorySemaphoreStorage implements SemaphoreStorage {\n private readonly semaphores = new Map<\n string,\n { total: number; available: number }\n >();\n\n /**\n * Attempts to acquire a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout or no permits available\n */\n async acquire(\n key: string,\n timeout: number = 30000,\n signal?: AbortSignal,\n ): Promise<boolean> {\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n // Check if aborted\n if (signal?.aborted) {\n throw new Error('Permit acquisition was aborted');\n }\n\n const semaphore = this.semaphores.get(key);\n if (semaphore && semaphore.available > 0) {\n semaphore.available--;\n return true;\n }\n await this.delay(10);\n }\n\n return false;\n }\n\n /**\n * Releases a permit for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\n async release(key: string): Promise<void> {\n const semaphore = this.semaphores.get(key);\n if (semaphore && semaphore.available < semaphore.total) {\n semaphore.available++;\n }\n }\n\n /**\n * Gets the number of available permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\n async getAvailablePermits(key: string): Promise<number> {\n const semaphore = this.semaphores.get(key);\n return semaphore ? semaphore.available : 0;\n }\n\n /**\n * Gets the total number of permits for a given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the total number of permits\n */\n async getTotalPermits(key: string): Promise<number> {\n const semaphore = this.semaphores.get(key);\n return semaphore ? semaphore.total : 0;\n }\n\n /**\n * Initializes a semaphore with the specified number of permits\n * @param key - The unique identifier for the semaphore\n * @param permits - The total number of permits to allocate\n */\n initialize(key: string, permits: number): void {\n this.semaphores.set(key, { total: permits, available: permits });\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n\n/**\n * Async semaphore implementation that controls access to a limited pool of resources.\n * Allows a specified number of concurrent operations while blocking additional requests.\n */\nexport class Semaphore {\n private storage: SemaphoreStorage;\n private readonly defaultPermits: number;\n private readonly defaultTimeout: number;\n\n /**\n * Creates a new semaphore instance\n * @param options - Configuration options for the semaphore\n */\n public constructor(options: SemaphoreOptions = {}) {\n this.storage = options.storage || new MemorySemaphoreStorage();\n this.defaultPermits = options.permits || 1;\n this.defaultTimeout = options.timeout || 30000;\n }\n\n /**\n * Sets the storage implementation for the semaphore\n * @param storage - The storage implementation to use\n */\n public setStorage(storage: SemaphoreStorage) {\n this.storage = storage;\n }\n\n /**\n * Gets the storage implementation for the semaphore\n * @returns The storage implementation\n */\n public getStorage(): SemaphoreStorage {\n return this.storage;\n }\n\n /**\n * Acquires a permit for the given key\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout\n */\n public async acquire(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<boolean> {\n // Initialize semaphore if it doesn't exist\n if (this.storage instanceof MemorySemaphoreStorage) {\n const totalPermits = await this.storage.getTotalPermits(key);\n if (totalPermits === 0) {\n (this.storage as MemorySemaphoreStorage).initialize(\n key,\n this.defaultPermits,\n );\n }\n }\n\n return this.storage.acquire(key, timeout || this.defaultTimeout, signal);\n }\n\n /**\n * Releases a permit for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\n public async release(key: string): Promise<void> {\n return this.storage.release(key);\n }\n\n /**\n * Gets the number of available permits for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\n public async getAvailablePermits(key: string): Promise<number> {\n return this.storage.getAvailablePermits(key);\n }\n\n /**\n * Gets the total number of permits for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the total number of permits\n */\n public async getTotalPermits(key: string): Promise<number> {\n return this.storage.getTotalPermits(key);\n }\n\n /**\n * Gets the number of acquired permits for the given key\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of acquired permits\n */\n public async getAcquiredPermits(key: string): Promise<number> {\n const total = await this.getTotalPermits(key);\n const available = await this.getAvailablePermits(key);\n return total - available;\n }\n\n /**\n * Executes a function with a permit from the semaphore\n * @param key - The unique identifier for the semaphore\n * @param fn - The function to execute with a permit\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the permit acquisition\n * @returns Promise resolving to the result of the function execution\n * @throws Error if permit acquisition fails or function execution fails\n */\n public async withPermit<T>(\n key: string,\n fn: () => Promise<T> | T,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<T> {\n const acquired = await this.acquire(key, timeout, signal);\n if (!acquired) {\n throw new Error(`Failed to acquire permit for key: ${key}`);\n }\n\n try {\n return await fn();\n } finally {\n await this.release(key);\n }\n }\n\n /**\n * Gets the current configuration of the semaphore\n * @returns Object containing the current permits and timeout values\n */\n public getConfig(): Omit<SemaphoreOptions, 'storage'> {\n return {\n permits: this.defaultPermits,\n timeout: this.defaultTimeout,\n };\n }\n}\n\n/**\n * Default semaphore instance for global use\n */\nexport const defaultSemaphore = new Semaphore();\n\n/**\n * Convenience function to execute a function with a permit using the default semaphore.\n *\n * @param key - The unique identifier for the semaphore\n * @param fn - The function to execute with a permit\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the permit acquisition\n * @returns Promise resolving to the result of the function execution\n *\n * @example\n * ```typescript\n * const controller = new AbortController();\n * const result = await withPermit('database-connection', async () => {\n * // This code runs with a permit from the semaphore\n * return await executeDatabaseQuery();\n * }, 30000, controller.signal);\n * controller.abort(); // Cancels the permit acquisition\n * ```\n */\nexport async function withPermit<T>(\n key: string,\n fn: () => Promise<T> | T,\n timeout?: number,\n signal?: AbortSignal,\n): Promise<T> {\n return defaultSemaphore.withPermit(key, fn, timeout, signal);\n}\n\n/**\n * Creates a new semaphore instance with the specified configuration\n * @param options - Configuration options for the semaphore\n * @returns New Semaphore instance\n *\n * @example\n * ```typescript\n * const semaphore = createSemaphore({\n * permits: 5,\n * timeout: 60000,\n * storage: new RedisSemaphoreStorage()\n * });\n * ```\n */\nexport function createSemaphore(options: SemaphoreOptions): Semaphore {\n return new Semaphore(options);\n}\n\n/**\n * Acquires a permit using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @param timeout - Optional timeout in milliseconds for permit acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if permit was acquired, false if timeout\n */\nexport async function acquirePermit(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n): Promise<boolean> {\n return defaultSemaphore.acquire(key, timeout, signal);\n}\n\n/**\n * Releases a permit using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @returns Promise that resolves when the permit is released\n */\nexport async function releasePermit(key: string): Promise<void> {\n return defaultSemaphore.release(key);\n}\n\n/**\n * Gets the number of available permits using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of available permits\n */\nexport async function getAvailablePermits(key: string): Promise<number> {\n return defaultSemaphore.getAvailablePermits(key);\n}\n\n/**\n * Gets the number of acquired permits using the default semaphore\n * @param key - The unique identifier for the semaphore\n * @returns Promise resolving to the number of acquired permits\n */\nexport async function getAcquiredPermits(key: string): Promise<number> {\n return defaultSemaphore.getAcquiredPermits(key);\n}\n"],"mappings":";;;;;;AA6DA,IAAa,yBAAb,MAAgE;CAC9D,AAAiB,6BAAa,IAAI,KAGjC;;;;;;;;CASD,MAAM,QACN,KACA,UAAkB,KAClB,QACmB;EACjB,MAAM,YAAY,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AAsB,mBAAmB,KAA8B;AACrE,QAAO,iBAAiB,mBAAmB,IAAI"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { JsonSerialize, SimpleProxy, createProxy, debounce, defer, devOnly, findAppDirectory, getCurrentDirectory, getSourceDirectories } from "../utilities-
|
|
1
|
+
import { JsonSerialize, SimpleProxy, createProxy, debounce, defer, devOnly, findAppDirectory, getCurrentDirectory, getSourceDirectories } from "../utilities-CQUaua43.js";
|
|
2
2
|
export { JsonSerialize, SimpleProxy, createProxy, debounce, defer, devOnly, findAppDirectory, getCurrentDirectory, getSourceDirectories };
|
package/dist/utils/utilities.js
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
1
1
|
require('../colors-DL3ucTiT.js');
|
|
2
|
-
require('../ActionRow-
|
|
2
|
+
require('../ActionRow-uJxU4UGo.js');
|
|
3
3
|
require('../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
5
|
-
require('../
|
|
6
|
-
require('../common-
|
|
7
|
-
require('../
|
|
8
|
-
require('../
|
|
9
|
-
require('../
|
|
10
|
-
require('../
|
|
11
|
-
require('../
|
|
12
|
-
require('../
|
|
13
|
-
require('../
|
|
14
|
-
require('../
|
|
15
|
-
require('../
|
|
16
|
-
require('../
|
|
17
|
-
require('../
|
|
18
|
-
require('../
|
|
19
|
-
require('../
|
|
20
|
-
require('../
|
|
21
|
-
require('../
|
|
22
|
-
require('../
|
|
23
|
-
require('../
|
|
24
|
-
require('../
|
|
25
|
-
require('../
|
|
26
|
-
require('../
|
|
27
|
-
require('../
|
|
28
|
-
require('../
|
|
29
|
-
require('../
|
|
30
|
-
require('../
|
|
31
|
-
require('../
|
|
32
|
-
require('../
|
|
33
|
-
require('../
|
|
34
|
-
require('../
|
|
35
|
-
require('../
|
|
36
|
-
require('../
|
|
4
|
+
const require_commandkit = require('../commandkit-DabqpQ6v.js');
|
|
5
|
+
require('../warning-CszH8HeS.js');
|
|
6
|
+
require('../common-0Iw8ZeM6.js');
|
|
7
|
+
require('../common-CCx-FJI4.js');
|
|
8
|
+
require('../container-DC0eQigs.js');
|
|
9
|
+
require('../file-DAUOZYhC.js');
|
|
10
|
+
require('../media-gallery-BLhwe5lO.js');
|
|
11
|
+
require('../section-BMcHN97i.js');
|
|
12
|
+
require('../separator-C___2K-f.js');
|
|
13
|
+
require('../text-display-BtQR88kY.js');
|
|
14
|
+
require('../label-D-uJWRZ0.js');
|
|
15
|
+
require('../poll-Bc6rjeUS.js');
|
|
16
|
+
require('../display-WDb9wMCv.js');
|
|
17
|
+
require('../element-DibzzA5L.js');
|
|
18
|
+
require('../types-TC4g3w91.js');
|
|
19
|
+
require('../EventInterceptor-BWoEJMHZ.js');
|
|
20
|
+
require('../constants-BMWH2YUr.js');
|
|
21
|
+
require('../PluginCommon-CPWV5xuX.js');
|
|
22
|
+
require('../CompilerPlugin-CZ4412Zm.js');
|
|
23
|
+
require('../RuntimePlugin-COeXe8rP.js');
|
|
24
|
+
require('../types-Cdh4uaFR.js');
|
|
25
|
+
require('../resolve-file-url-CJoD0FAn.js');
|
|
26
|
+
require('../runtime-Skt5NiOc.js');
|
|
27
|
+
require('../utils-Br3eenD1.js');
|
|
28
|
+
require('../types-package-D11rQXLs.js');
|
|
29
|
+
require('../constants-D0dawKxO.js');
|
|
30
|
+
require('../EventWorkerContext-D_9q1Bm2.js');
|
|
31
|
+
require('../signals-Cnqe9dFV.js');
|
|
32
|
+
require('../helpers-D2_1jih6.js');
|
|
33
|
+
require('../MessageCommandParser-CKh-tM97.js');
|
|
34
|
+
require('../CommandsRouter-CWMipIis.js');
|
|
35
|
+
require('../EventsRouter-C04XqRKf.js');
|
|
36
|
+
require('../router-BvamdzoF.js');
|
|
37
|
+
require('../common-fIO6fqGZ.js');
|
|
38
|
+
require('../CommandKitEventsChannel-2l9Za-le.js');
|
|
39
|
+
require('../store-ZwL2gN6a.js');
|
|
37
40
|
|
|
38
41
|
exports.JsonSerialize = require_commandkit.JsonSerialize;
|
|
39
42
|
exports.createProxy = require_commandkit.createProxy;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/utils/
|
|
1
|
+
//#region src/utils/warning.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Emit a warning message to the console as a CommandKitWarning.
|
|
4
4
|
* @param message - The warning message to emit.
|
|
@@ -11,6 +11,15 @@ declare function emitWarning(message: string, code?: string): void;
|
|
|
11
11
|
* @example warnUnstable('MyUnstableFeature');
|
|
12
12
|
*/
|
|
13
13
|
declare function warnUnstable(name: string): void;
|
|
14
|
+
declare function warnDeprecated({
|
|
15
|
+
what,
|
|
16
|
+
message,
|
|
17
|
+
where
|
|
18
|
+
}: {
|
|
19
|
+
what: string;
|
|
20
|
+
where?: string;
|
|
21
|
+
message?: string;
|
|
22
|
+
}): void;
|
|
14
23
|
//#endregion
|
|
15
|
-
export { emitWarning, warnUnstable };
|
|
16
|
-
//# sourceMappingURL=
|
|
24
|
+
export { emitWarning, warnDeprecated, warnUnstable };
|
|
25
|
+
//# sourceMappingURL=warning.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-Bf-3Eevb.js","names":[],"sources":["../src/cli/utils.ts"],"sourcesContent":["import type { Ora } from 'ora';\n\nlet ora: typeof import('ora') | undefined;\n\n/**\n * @private\n * @internal\n */\nexport async function createSpinner(text: string): Promise<Ora> {\n if (!ora) {\n ora = await import('ora');\n }\n\n return (ora.default || ora)({\n text,\n color: 'cyan',\n });\n}\n"],"mappings":";;AAEA,IAAI;;;;;AAMJ,eAAsB,cAAc,MAA4B;AAC9D,KAAI,CAAC,IACH,OAAM,MAAM,OAAO;AAGrB,SAAQ,IAAI,WAAW,KAAK;EAC1B;EACA,OAAO;EACR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-Br3eenD1.js","names":[],"sources":["../src/config/utils.ts"],"sourcesContent":["import { CommandKitConfig } from './types';\n\n/**\n * @private\n */\nexport type DeepRequired<T, OptionalKeys extends keyof T = never> = {\n [P in keyof T]-?: P extends OptionalKeys ? Partial<T[P]> : DeepRequired<T[P]>;\n};\n\n/**\n * @private\n */\nexport type DeepPartial<T> = {\n [P in keyof T]?: DeepPartial<T[P]>;\n};\n\n/**\n * @private\n * @example\n * ```ts\n * const target = { a: 1, b: { c: 2 } };\n * const source = { b: { d: 3 } };\n * const result = mergeDeep(target, source);\n * // result = { a: 1, b: { c: 2, d: 3 } }\n * ```\n */\nexport const mergeDeep = <T extends Record<string, any>>(\n target: T,\n source?: T,\n tracker = new WeakMap<object, boolean>(),\n): T => {\n if (!source) return target;\n const isObject = (obj: unknown) =>\n obj && typeof obj === 'object' && !Array.isArray(obj);\n\n // Prevent infinite recursion\n if (tracker.has(target)) {\n return target;\n }\n\n // Mark the target as visited\n tracker.set(target, true);\n\n const output: T = { ...target };\n if (isObject(target) && isObject(source)) {\n Object.keys(source).forEach((key) => {\n if (isObject(source[key])) {\n if (!(key in target)) {\n Object.assign(output, { [key]: source[key] });\n } else {\n output[key as keyof T] = mergeDeep(target[key], source[key], tracker);\n }\n } else {\n Object.assign(output, { [key]: source[key] });\n }\n });\n }\n\n return output as T;\n};\n\nexport type ResolvedCommandKitConfig = DeepRequired<\n CommandKitConfig,\n 'compilerOptions'\n>;\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAa,aACb,QACA,QACA,0BAAU,IAAI,SAA0B,KACjC;AACL,KAAI,CAAC,OAAQ,QAAO;CACpB,MAAM,YAAY,QAClB,OAAO,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,IAAI;AAGrD,KAAI,QAAQ,IAAI,OAAO,CACrB,QAAO;AAIT,SAAQ,IAAI,QAAQ,KAAK;CAEzB,MAAM,SAAY,EAAE,GAAG,QAAQ;AAC/B,KAAI,SAAS,OAAO,IAAI,SAAS,OAAO,CACtC,QAAO,KAAK,OAAO,CAAC,SAAS,QAAQ;AACnC,MAAI,SAAS,OAAO,KAAK,CACvB,KAAI,EAAE,OAAO,QACX,QAAO,OAAO,QAAQ,GAAG,MAAM,OAAO,MAAM,CAAC;MAE7C,QAAO,OAAkB,UAAU,OAAO,MAAM,OAAO,MAAM,QAAQ;MAGvE,QAAO,OAAO,QAAQ,GAAG,MAAM,OAAO,MAAM,CAAC;GAE/C;AAGJ,QAAO"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* The current version of CommandKit.
|
|
8
8
|
*/
|
|
9
|
-
const version = "1.2.0-rc.
|
|
9
|
+
const version = "1.2.0-rc.12";
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
12
12
|
Object.defineProperty(exports, 'version', {
|
|
@@ -15,4 +15,4 @@ Object.defineProperty(exports, 'version', {
|
|
|
15
15
|
return version;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
//# sourceMappingURL=version
|
|
18
|
+
//# sourceMappingURL=version-DC4j2ZwU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version
|
|
1
|
+
{"version":3,"file":"version-DC4j2ZwU.js","names":[],"sources":["../src/version.ts"],"sourcesContent":["/**\n * @private\n */\nfunction $version(): string {\n 'use macro';\n return require('../package.json').version;\n}\n\n/**\n * The current version of CommandKit.\n */\nexport const version: string = $version();\n"],"mappings":";;;;;;;;AAWA,MAAa,UAA4B"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { version } from "./version-
|
|
1
|
+
import { version } from "./version-DggMfP_1.js";
|
|
2
2
|
export { version };
|
package/dist/version.js
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/warning.ts
|
|
3
|
+
const WARNED_KEYS = /* @__PURE__ */ new Set();
|
|
4
|
+
const DEPRECATED_KEYS = /* @__PURE__ */ new Set();
|
|
5
|
+
/**
|
|
6
|
+
* Emit a warning message to the console as a CommandKitWarning.
|
|
7
|
+
* @param message - The warning message to emit.
|
|
8
|
+
* @param code - The warning code (default is 'CommandKitWarning').
|
|
9
|
+
*/
|
|
10
|
+
function emitWarning(message, code = "CommandKitWarning") {
|
|
11
|
+
process.emitWarning(message, { code });
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Emit a warning for unstable features in CommandKit.
|
|
15
|
+
* @param name - The name of the unstable feature.
|
|
16
|
+
* @example warnUnstable('MyUnstableFeature');
|
|
17
|
+
*/
|
|
18
|
+
function warnUnstable(name) {
|
|
19
|
+
if (WARNED_KEYS.has(name)) return;
|
|
20
|
+
WARNED_KEYS.add(name);
|
|
21
|
+
emitWarning(`${name} is unstable and may change in future versions.`, "CommandKitUnstableWarning");
|
|
22
|
+
}
|
|
23
|
+
function warnDeprecated({ what, message, where }) {
|
|
24
|
+
const name = `${what}:${where}`;
|
|
25
|
+
if (DEPRECATED_KEYS.has(name)) return;
|
|
26
|
+
DEPRECATED_KEYS.add(name);
|
|
27
|
+
emitWarning([
|
|
28
|
+
`${what} is deprecated`,
|
|
29
|
+
where ? `in ${where}` : "",
|
|
30
|
+
message || "and may be removed in future versions."
|
|
31
|
+
].filter(Boolean).join(" "), "CommandKitDeprecatedWarning");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
Object.defineProperty(exports, 'emitWarning', {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () {
|
|
38
|
+
return emitWarning;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, 'warnDeprecated', {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return warnDeprecated;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, 'warnUnstable', {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return warnUnstable;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=warning-CszH8HeS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warning-CszH8HeS.js","names":[],"sources":["../src/utils/warning.ts"],"sourcesContent":["const WARNED_KEYS = new Set<string>();\nconst DEPRECATED_KEYS = new Set<string>();\n\n/**\n * Emit a warning message to the console as a CommandKitWarning.\n * @param message - The warning message to emit.\n * @param code - The warning code (default is 'CommandKitWarning').\n */\nexport function emitWarning(message: string, code = 'CommandKitWarning') {\n process.emitWarning(message, { code });\n}\n\n/**\n * Emit a warning for unstable features in CommandKit.\n * @param name - The name of the unstable feature.\n * @example warnUnstable('MyUnstableFeature');\n */\nexport function warnUnstable(name: string) {\n if (WARNED_KEYS.has(name)) return;\n\n WARNED_KEYS.add(name);\n\n emitWarning(\n `${name} is unstable and may change in future versions.`,\n 'CommandKitUnstableWarning',\n );\n}\nexport function warnDeprecated({\n what,\n message,\n where,\n}: {\n what: string;\n where?: string;\n message?: string;\n}) {\n const name = `${what}:${where}`;\n\n if (DEPRECATED_KEYS.has(name)) return;\n\n DEPRECATED_KEYS.add(name);\n\n emitWarning(\n [\n `${what} is deprecated`,\n where ? `in ${where}` : '',\n message || 'and may be removed in future versions.',\n ]\n .filter(Boolean)\n .join(' '),\n 'CommandKitDeprecatedWarning',\n );\n}\n"],"mappings":";;AAAA,MAAM,8BAAc,IAAI,KAAa;AACrC,MAAM,kCAAkB,IAAI,KAAa;;;;;;AAOzC,SAAgB,YAAY,SAAiB,OAAO,qBAAqB;AACvE,SAAQ,YAAY,SAAS,EAAE,MAAM,CAAC;;;;;;;AAQxC,SAAgB,aAAa,MAAc;AACzC,KAAI,YAAY,IAAI,KAAK,CAAE;AAE3B,aAAY,IAAI,KAAK;AAErB,aACE,GAAG,KAAK,kDACR,4BACD;;AAEH,SAAgB,eAAe,EAC7B,MACA,SACA,SAKC;CACD,MAAM,OAAO,GAAG,KAAK,GAAG;AAExB,KAAI,gBAAgB,IAAI,KAAK,CAAE;AAE/B,iBAAgB,IAAI,KAAK;AAEzB,aACE;EACA,GAAG,KAAK;EACR,QAAQ,MAAM,UAAU;EACxB,WAAW;EAAyC,CAEpD,OAAO,QAAQ,CACf,KAAK,IAAI,EACT,8BACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commandkit",
|
|
3
3
|
"description": "Beginner friendly command & event handler for Discord.js",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.12",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -176,11 +176,11 @@
|
|
|
176
176
|
"@types/ms": "^2.0.0",
|
|
177
177
|
"@types/node": "^22.10.2",
|
|
178
178
|
"@types/yargs": "^17.0.32",
|
|
179
|
-
"discord.js": "^14.
|
|
179
|
+
"discord.js": "^14.23.2",
|
|
180
180
|
"tsx": "^4.19.2",
|
|
181
181
|
"typescript": "^5.7.3",
|
|
182
182
|
"vitest": "^3.0.5",
|
|
183
|
-
"tsconfig": "0.0.0-rc.
|
|
183
|
+
"tsconfig": "0.0.0-rc.12"
|
|
184
184
|
},
|
|
185
185
|
"engines": {
|
|
186
186
|
"node": ">=24"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRow-CbdGFWMT.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,6BAAkB;AAElC,KAAI,MAAM,QAAQ,MAAM,SAAS,CAE/B,KAAI,cAAc,GAAG,MAAM,SAAS;UAC3B,MAAM,SAEf,KAAI,cAAc,MAAM,SAAS;AAGnC,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventWorkerContext-Dq29tieI.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,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-process-cj2vF12T.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 baseArgs = [\n `--title=\"CommandKit ${isDev ? 'Development' : 'Production'}\"`,\n '--enable-source-maps',\n ];\n\n const nodeOptions = process.env.NODE_OPTIONS;\n let nodeArgs = [...baseArgs];\n\n if (nodeOptions) {\n const options = nodeOptions.trim().split(/\\s+/);\n\n for (const option of options) {\n const optionName = option.split('=')[0];\n const existingIndex = nodeArgs.findIndex((arg) =>\n arg.startsWith(optionName),\n );\n\n if (existingIndex !== -1) {\n nodeArgs[existingIndex] = option;\n } else {\n nodeArgs.push(option);\n }\n }\n }\n\n nodeArgs.push(fileName);\n\n const ps = spawn('node', nodeArgs, {\n cwd,\n windowsHide: true,\n env: isDev ? DevEnv() : ProdEnv(),\n stdio,\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;EAAM;AAGxC,QAAO;EAAC;EAAQ;EAAQ;EAAO;;;;;;AAOjC,SAAgB,iBAChB,UACA,KACA,OACA;;AACE,KAAI,6CAAiB,KAAK,SAAS,CAAC,CAClC,sBAAM,yCAAyC,WAAW;CAG5D,MAAM,QAAQ,SAAS,MAAM;CAE7B,MAAM,WAAW,CACjB,uBAAuB,QAAQ,gBAAgB,aAAa,IAC5D,uBAAuB;CAGvB,MAAM,cAAc,QAAQ,IAAI;CAChC,IAAI,WAAW,CAAC,GAAG,SAAS;AAE5B,KAAI,aAAa;EACf,MAAM,UAAU,YAAY,MAAM,CAAC,MAAM,MAAM;AAE/C,OAAK,MAAM,UAAU,SAAS;GAC5B,MAAM,aAAa,OAAO,MAAM,IAAI,CAAC;GACrC,MAAM,gBAAgB,SAAS,WAAW,QAC1C,IAAI,WAAW,WAAW,CACzB;AAED,OAAI,kBAAkB,GACpB,UAAS,iBAAiB;OAE1B,UAAS,KAAK,OAAO;;;AAK3B,UAAS,KAAK,SAAS;CAEvB,MAAM,mCAAW,QAAQ,UAAU;EACjC;EACA,aAAa;EACb,KAAK,QAAQ,oBAAQ,GAAG,qBAAS;EACjC;EACD,CAAC;AAEF,kBAAG,wDAAQ,KAAK,QAAQ,OAAO;AAC/B,kBAAG,wDAAQ,KAAK,QAAQ,OAAO;AAE/B,QAAO"}
|