commandkit 1.2.0-rc.12 → 1.2.0-rc.13
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/{COPYING.md → LICENSE.md} +3 -3
- package/README.md +3 -3
- package/bin/index.mjs +1 -1
- package/cli.d.ts +19 -0
- package/config.cjs +3 -0
- package/config.d.ts +1 -0
- package/dist/{ActionRow-B-7n9MMr.d.ts → ActionRow-B-CGmjDp.d.ts} +3 -4
- package/dist/{ActionRow-uJxU4UGo.js → ActionRow-CSN_UKmM.js} +2 -3
- package/dist/{ActionRow-uJxU4UGo.js.map → ActionRow-CSN_UKmM.js.map} +1 -1
- package/dist/{Button-RMp-w8HV.d.ts → Button-C-GPeFA3.d.ts} +6 -7
- package/dist/{ButtonKit-9k4yfhYD.d.ts → ButtonKit-DKu0VAe4.d.ts} +36 -37
- package/dist/ChannelSelectMenuKit-HQZ4hH5s.d.ts +66 -0
- package/dist/{CommandKitEventsChannel-2l9Za-le.js → CommandKitEventsChannel-CnT5ymYe.js} +2 -2
- package/dist/{CommandKitEventsChannel-2l9Za-le.js.map → CommandKitEventsChannel-CnT5ymYe.js.map} +1 -1
- package/dist/{CommandsRouter-CBdsqaWK.d.ts → CommandsRouter-C7dZEepB.d.ts} +49 -50
- package/dist/{CommandsRouter-CWMipIis.js → CommandsRouter-C_HLsrGX.js} +2 -6
- package/dist/{CommandsRouter-CWMipIis.js.map → CommandsRouter-C_HLsrGX.js.map} +1 -1
- package/dist/{CompilerPlugin-CZ4412Zm.js → CompilerPlugin-CUsGAfgl.js} +2 -2
- package/dist/{CompilerPlugin-CZ4412Zm.js.map → CompilerPlugin-CUsGAfgl.js.map} +1 -1
- package/dist/EventInterceptor-BWoEJMHZ.js.map +1 -1
- package/dist/{EventInterceptor-x-R2qshQ.d.ts → EventInterceptor-CZmWpS08.d.ts} +40 -40
- package/dist/{EventWorkerContext-D_9q1Bm2.js → EventWorkerContext-Dfhgv329.js} +2 -3
- package/dist/{EventWorkerContext-D_9q1Bm2.js.map → EventWorkerContext-Dfhgv329.js.map} +1 -1
- package/dist/EventsRouter-DZ37r54v.d.ts +90 -0
- package/dist/{EventsRouter-C04XqRKf.js → EventsRouter-DZYIha6m.js} +2 -6
- package/dist/{EventsRouter-C04XqRKf.js.map → EventsRouter-DZYIha6m.js.map} +1 -1
- package/dist/MentionableSelectMenuKit-7URDUM3-.d.ts +61 -0
- package/dist/{MessageCommandParser-CKh-tM97.js → MessageCommandParser-Bs9fimmd.js} +2 -3
- package/dist/{MessageCommandParser-CKh-tM97.js.map → MessageCommandParser-Bs9fimmd.js.map} +1 -1
- package/dist/MessageCommandParser-q3dQcE5N.d.ts +194 -0
- package/dist/{Modal-Calb46SJ.d.ts → Modal-CZT9MZsy.d.ts} +20 -10
- package/dist/{ModalKit-Cq2ns6jv.d.ts → ModalKit-BWXI3Z26.d.ts} +33 -34
- package/dist/{PluginCommon-CPWV5xuX.js → PluginCommon-BLxWww5u.js} +6 -7
- package/dist/{PluginCommon-CPWV5xuX.js.map → PluginCommon-BLxWww5u.js.map} +1 -1
- package/dist/RoleSelectMenuKit-BY-JJ18w.d.ts +66 -0
- package/dist/{RuntimePlugin-COeXe8rP.js → RuntimePlugin-CtobluSU.js} +2 -2
- package/dist/{RuntimePlugin-COeXe8rP.js.map → RuntimePlugin-CtobluSU.js.map} +1 -1
- package/dist/{SelectMenu-VcDhOGoJ.d.ts → SelectMenu-q_b3Mjv9.d.ts} +9 -10
- package/dist/StringSelectMenuKit-lVhUMc3g.d.ts +66 -0
- package/dist/UserSelectMenuKit-CCj4Fpkr.d.ts +66 -0
- package/dist/analytics/analytics-engine.d.ts +1 -33
- package/dist/analytics/analytics-engine.js +22 -37
- package/dist/analytics/analytics-provider.d.ts +1 -33
- package/dist/analytics/constants.js +1 -1
- package/dist/analytics/utils.js +22 -37
- package/dist/{analytics-engine-NOInIjv8.d.ts → analytics-engine-WQhXmx3H.d.ts} +844 -841
- package/dist/app/commands/AppCommandRunner.d.ts +1 -33
- package/dist/app/commands/AppCommandRunner.js +22 -37
- package/dist/app/commands/Context.d.ts +1 -33
- package/dist/app/commands/Context.js +22 -37
- package/dist/app/commands/MessageCommandParser.d.ts +1 -1
- package/dist/app/commands/MessageCommandParser.js +1 -2
- package/dist/app/commands/helpers.d.ts +1 -1
- package/dist/app/commands/helpers.js +1 -1
- package/dist/app/events/EventWorkerContext.d.ts +42 -35
- package/dist/app/events/EventWorkerContext.js +1 -1
- package/dist/app/handlers/AppCommandHandler.d.ts +1 -33
- package/dist/app/handlers/AppCommandHandler.js +22 -37
- package/dist/app/handlers/AppEventsHandler.d.ts +1 -33
- package/dist/app/handlers/AppEventsHandler.js +22 -37
- package/dist/app/index.d.ts +4 -33
- package/dist/app/index.js +22 -38
- package/dist/app/interrupt/signals.d.ts +1 -1
- package/dist/app/interrupt/signals.js +2 -3
- package/dist/app/middlewares/permissions.d.ts +1 -33
- package/dist/app/middlewares/permissions.js +22 -37
- package/dist/app/register/CommandRegistrar.d.ts +1 -33
- package/dist/app/register/CommandRegistrar.js +22 -37
- 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 +2 -3
- package/dist/app/router/index.js +2 -2
- package/dist/{chunk-nOFOJqeH.js → chunk-kSYXY2_d.js} +10 -6
- package/dist/cli/app-process.d.ts +0 -1
- package/dist/cli/app-process.js +62 -7
- package/dist/cli/app-process.js.map +1 -0
- package/dist/cli/build.d.ts +2 -33
- package/dist/cli/build.js +189 -42
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/common.d.ts +1 -33
- package/dist/cli/common.js +4 -4
- package/dist/cli/development.d.ts +18 -1
- package/dist/cli/development.js +41 -49
- package/dist/cli/development.js.map +1 -1
- package/dist/cli/env.d.ts +4 -0
- package/dist/cli/env.js +1 -1
- package/dist/cli/generators.js +5 -8
- package/dist/cli/generators.js.map +1 -1
- package/dist/cli/information.js +5 -5
- package/dist/cli/information.js.map +1 -1
- package/dist/cli/init.d.ts +12 -2
- package/dist/cli/init.js +100 -39
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/production.d.ts +0 -1
- package/dist/cli/production.js +36 -49
- package/dist/cli/production.js.map +1 -1
- package/dist/cli/type-checker.js +5 -5
- package/dist/cli/utils.d.ts +0 -1
- package/dist/cli/utils.js +17 -2
- package/dist/cli/utils.js.map +1 -0
- package/dist/{colors-DL3ucTiT.js → colors-Csc0X4QJ.js} +2 -3
- package/dist/{colors-DL3ucTiT.js.map → colors-Csc0X4QJ.js.map} +1 -1
- package/dist/{commandkit-DabqpQ6v.js → commandkit-SIjTLD2R.js} +145 -46
- package/dist/commandkit-SIjTLD2R.js.map +1 -0
- package/dist/commandkit.d.ts +1 -33
- package/dist/commandkit.js +22 -37
- package/dist/{common-CCx-FJI4.js → common-CEordwf3.js} +1 -1
- package/dist/{common-CCx-FJI4.js.map → common-CEordwf3.js.map} +1 -1
- package/dist/{common-fIO6fqGZ.js → common-DSRs_mfw.js} +9 -12
- package/dist/{common-fIO6fqGZ.js.map → common-DSRs_mfw.js.map} +1 -1
- package/dist/{common-DHTTnX82.d.ts → common-DnwCYit8.d.ts} +3 -4
- package/dist/components/common/EventInterceptor.d.ts +1 -1
- package/dist/components/common/element.d.ts +1 -4
- package/dist/components/common/types.d.ts +1 -1
- package/dist/components/common/types.js +0 -1
- package/dist/components/display/common.d.ts +0 -1
- package/dist/components/display/common.js +1 -1
- package/dist/components/display/container.d.ts +1 -1
- package/dist/components/display/container.js +1 -2
- package/dist/components/display/file.d.ts +1 -1
- package/dist/components/display/file.js +1 -1
- package/dist/components/display/index.d.ts +8 -9
- package/dist/components/display/index.js +8 -9
- package/dist/components/display/label.d.ts +1 -1
- package/dist/components/display/label.js +1 -2
- package/dist/components/display/media-gallery.d.ts +1 -1
- package/dist/components/display/media-gallery.js +1 -2
- package/dist/components/display/poll.d.ts +1 -1
- package/dist/components/display/poll.js +1 -1
- package/dist/components/display/section.d.ts +1 -1
- package/dist/components/display/section.js +1 -2
- package/dist/components/display/separator.d.ts +1 -1
- package/dist/components/display/separator.js +1 -1
- package/dist/components/display/text-display.d.ts +1 -1
- package/dist/components/display/text-display.js +1 -1
- package/dist/components/index.d.ts +23 -26
- package/dist/components/index.js +23 -36
- package/dist/components/interactive/action-row/ActionRow.d.ts +1 -5
- package/dist/components/interactive/action-row/ActionRow.js +1 -1
- package/dist/components/interactive/button/Button.d.ts +1 -6
- package/dist/components/interactive/button/Button.js +22 -37
- package/dist/components/interactive/button/ButtonKit.d.ts +1 -2
- package/dist/components/interactive/button/ButtonKit.js +22 -37
- package/dist/components/interactive/modal/Modal.d.ts +2 -7
- package/dist/components/interactive/modal/Modal.js +23 -37
- package/dist/components/interactive/modal/ModalKit.d.ts +1 -2
- package/dist/components/interactive/modal/ModalKit.js +22 -37
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.d.ts +1 -3
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.js +22 -37
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.d.ts +1 -3
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.js +22 -37
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.d.ts +1 -3
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.js +22 -37
- package/dist/components/interactive/select-menu/SelectMenu.d.ts +1 -9
- package/dist/components/interactive/select-menu/SelectMenu.js +22 -37
- package/dist/components/interactive/select-menu/StringSelectMenuKit.d.ts +1 -3
- package/dist/components/interactive/select-menu/StringSelectMenuKit.js +22 -37
- package/dist/components/interactive/select-menu/UserSelectMenuKit.d.ts +1 -3
- package/dist/components/interactive/select-menu/UserSelectMenuKit.js +22 -37
- package/dist/components/interactive/select-menu/common.d.ts +1 -2
- package/dist/components/interactive/select-menu/common.js +0 -1
- package/dist/config/config.d.ts +15 -35
- package/dist/config/config.js +22 -37
- package/dist/config/default.d.ts +1 -33
- package/dist/config/default.js +22 -37
- package/dist/config/loader.d.ts +1 -33
- package/dist/config/loader.js +22 -37
- package/dist/config/types.d.ts +1 -33
- package/dist/config/utils.d.ts +1 -33
- package/dist/constants-BFFK-hfP.js +27 -0
- package/dist/{constants-AH-9qJ89.js.map → constants-BFFK-hfP.js.map} +1 -1
- package/dist/{constants-DqnSDZ6l.d.ts → constants-CuYW0K10.d.ts} +14 -8
- package/dist/{constants-D0dawKxO.js → constants-Cw8VjCVz.js} +2 -3
- package/dist/{constants-D0dawKxO.js.map → constants-Cw8VjCVz.js.map} +1 -1
- package/dist/{constants-BMWH2YUr.js → constants-CxkFFZ7p.js} +16 -1
- package/dist/constants-CxkFFZ7p.js.map +1 -0
- package/dist/{constants-CCFSX2NG.d.ts → constants-EpKcj0dH.d.ts} +2 -2
- package/dist/{container-DC0eQigs.js → container-DCPljKVH.js} +3 -4
- package/dist/{container-DC0eQigs.js.map → container-DCPljKVH.js.map} +1 -1
- package/dist/{container-1ltvkavy.d.ts → container-DYcb7zGw.d.ts} +2 -3
- package/dist/context/async-context.d.ts +1 -33
- package/dist/context/async-context.js +22 -37
- package/dist/context/environment.d.ts +1 -33
- package/dist/context/environment.js +22 -37
- package/dist/element-DibzzA5L.js.map +1 -1
- package/dist/{element-CvNhvLZ8.d.ts → element-wQo0heGj.d.ts} +4 -5
- package/dist/{env-8yY-6pbC.js → env-CmspDhHy.js} +7 -3
- package/dist/env-CmspDhHy.js.map +1 -0
- package/dist/error-codes-Ds0bnPvT.js.map +1 -1
- package/dist/events/CommandKitEventsChannel.d.ts +1 -33
- package/dist/events/CommandKitEventsChannel.js +1 -1
- package/dist/{file-DAUOZYhC.js → file-Ca1kpEtE.js} +2 -3
- package/dist/{file-DAUOZYhC.js.map → file-Ca1kpEtE.js.map} +1 -1
- package/dist/{file-n2yl_-vl.d.ts → file-CrV4lSnl.d.ts} +2 -3
- package/dist/flags/FlagProvider.d.ts +1 -33
- package/dist/flags/feature-flags.d.ts +1 -33
- package/dist/flags/feature-flags.js +163 -41
- package/dist/flags/feature-flags.js.map +1 -0
- package/dist/flags/store.d.ts +1 -33
- package/dist/flags/store.js +1 -1
- package/dist/{helpers-hDh_tMb6.d.ts → helpers-AQPLVY35.d.ts} +2 -3
- package/dist/{helpers-D2_1jih6.js → helpers-Btx1FSZx.js} +2 -3
- package/dist/{helpers-D2_1jih6.js.map → helpers-Btx1FSZx.js.map} +1 -1
- package/dist/index.d.ts +41 -44
- package/dist/index.js +39 -45
- package/dist/index.js.map +1 -1
- package/dist/kv/constants.d.ts +1 -1
- package/dist/kv/constants.js +1 -1
- package/dist/kv/dotprops.js +25 -3
- package/dist/kv/dotprops.js.map +1 -0
- package/dist/kv/kv.d.ts +289 -290
- package/dist/kv/kv.js +14 -16
- package/dist/kv/kv.js.map +1 -1
- package/dist/kv/serde.d.ts +12 -3
- package/dist/kv/serde.js +86 -4
- package/dist/kv/serde.js.map +1 -0
- package/dist/{label-D0KXeBhk.d.ts → label-37kaNWMH.d.ts} +4 -5
- package/dist/{label-D-uJWRZ0.js → label-B6vXvwLM.js} +4 -5
- package/dist/{label-D-uJWRZ0.js.map → label-B6vXvwLM.js.map} +1 -1
- package/dist/logger/DefaultLogger.d.ts +66 -3
- package/dist/logger/DefaultLogger.js +22 -37
- package/dist/logger/ILogger.d.ts +64 -2
- package/dist/logger/ILogger.js +0 -1
- package/dist/logger/Logger.d.ts +36 -3
- package/dist/logger/Logger.js +22 -37
- package/dist/logger/NoopLogger.d.ts +36 -37
- package/dist/{media-gallery-BzG70ued.d.ts → media-gallery-Ci3I4ElH.d.ts} +2 -3
- package/dist/{media-gallery-BLhwe5lO.js → media-gallery-u3gjX7yD.js} +3 -4
- package/dist/{media-gallery-BLhwe5lO.js.map → media-gallery-u3gjX7yD.js.map} +1 -1
- package/dist/plugins/CompilerPlugin.d.ts +1 -33
- package/dist/plugins/CompilerPlugin.js +1 -2
- package/dist/plugins/PluginCommon.d.ts +1 -33
- package/dist/plugins/PluginCommon.js +1 -1
- package/dist/plugins/RuntimePlugin.d.ts +1 -33
- package/dist/plugins/RuntimePlugin.js +1 -2
- package/dist/plugins/index.d.ts +1 -33
- package/dist/plugins/index.js +24 -37
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +1 -33
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +22 -37
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +1 -33
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +22 -37
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +1 -33
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +22 -37
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +1 -33
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +22 -37
- package/dist/plugins/plugin-runtime/runtime.d.ts +1 -33
- package/dist/plugins/plugin-runtime/runtime.js +0 -1
- package/dist/plugins/types.d.ts +1 -33
- package/dist/plugins/types.js +0 -1
- package/dist/{poll-Bc6rjeUS.js → poll-CFe8yvoJ.js} +12 -13
- package/dist/{poll-Bc6rjeUS.js.map → poll-CFe8yvoJ.js.map} +1 -1
- package/dist/{poll-HnaJcB0o.d.ts → poll-Ddtapd6n.d.ts} +8 -9
- package/dist/{resolve-file-url-CJoD0FAn.js → resolve-file-url-CdHqwWs3.js} +2 -2
- package/dist/{resolve-file-url-CJoD0FAn.js.map → resolve-file-url-CdHqwWs3.js.map} +1 -1
- package/dist/{section-BMcHN97i.js → section-BC8LF-B2.js} +3 -4
- package/dist/{section-BMcHN97i.js.map → section-BC8LF-B2.js.map} +1 -1
- package/dist/{section-BOaJKXiy.d.ts → section-DkUKULnB.d.ts} +2 -3
- package/dist/{separator-C___2K-f.js → separator-BUTiW7uz.js} +2 -3
- package/dist/{separator-C___2K-f.js.map → separator-BUTiW7uz.js.map} +1 -1
- package/dist/{separator-Cb7-6T6N.d.ts → separator-CbXsIFCa.d.ts} +2 -3
- package/dist/{signals-Cnqe9dFV.js → signals-B8z1wJ6W.js} +2 -2
- package/dist/{signals-Cnqe9dFV.js.map → signals-B8z1wJ6W.js.map} +1 -1
- package/dist/{signals-DBS60vTo.d.ts → signals-BbTgTc0i.d.ts} +2 -2
- package/dist/{store-ZwL2gN6a.js → store-D8r_hryO.js} +2 -3
- package/dist/{store-ZwL2gN6a.js.map → store-D8r_hryO.js.map} +1 -1
- package/dist/{text-display-B_hpz50P.d.ts → text-display-D7j39VC-.d.ts} +2 -3
- package/dist/{text-display-BtQR88kY.js → text-display-DANahMN3.js} +2 -3
- package/dist/{text-display-BtQR88kY.js.map → text-display-DANahMN3.js.map} +1 -1
- package/dist/{type-checker-CEFHoQoV.js → type-checker-cVd3Hpnh.js} +4 -6
- package/dist/{type-checker-CEFHoQoV.js.map → type-checker-cVd3Hpnh.js.map} +1 -1
- package/dist/{types-CJ-XvOFN.d.ts → types-BywA9d2Z.d.ts} +2 -2
- package/dist/{types-package-D11rQXLs.js → types-package-CsTNfvv2.js} +3 -6
- package/dist/{types-package-D11rQXLs.js.map → types-package-CsTNfvv2.js.map} +1 -1
- package/dist/types.d.ts +1 -33
- package/dist/utils/colors.js +1 -1
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +3 -2
- package/dist/utils/dev-hooks.d.ts +1 -33
- package/dist/utils/dev-hooks.js +22 -37
- package/dist/utils/error-codes.d.ts +54 -2
- package/dist/utils/resolve-file-url.d.ts +11 -2
- package/dist/utils/resolve-file-url.js +1 -1
- package/dist/utils/types-package.js +2 -2
- package/dist/utils/useful-stuff/async-queue.d.ts +21 -21
- package/dist/utils/useful-stuff/mutex.d.ts +62 -62
- package/dist/utils/useful-stuff/ratelimiter.d.ts +56 -56
- package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
- package/dist/utils/useful-stuff/semaphore.d.ts +82 -82
- package/dist/utils/utilities.d.ts +113 -2
- package/dist/utils/utilities.js +25 -38
- package/dist/utils-Br3eenD1.js.map +1 -1
- package/dist/version.d.ts +8 -2
- package/dist/version.js +12 -2
- package/dist/version.js.map +1 -0
- package/dist/warning-CszH8HeS.js.map +1 -1
- package/hooks.cjs +11 -4
- package/package.json +14 -7
- package/dist/ChannelSelectMenuKit-CsYgIyKe.d.ts +0 -67
- package/dist/DefaultLogger-CHMVsizQ.d.ts +0 -67
- package/dist/EventWorkerContext-CLhZRHhH.d.ts +0 -43
- package/dist/EventsRouter-4pT6vj-U.d.ts +0 -90
- package/dist/ILogger-BQ2ew4zR.d.ts +0 -64
- package/dist/Logger-DyV7oli4.d.ts +0 -37
- package/dist/MentionableSelectMenuKit-CO9phWMf.d.ts +0 -62
- package/dist/MessageCommandParser-DEOl_ifb.d.ts +0 -195
- package/dist/RoleSelectMenuKit-DvBxzpWh.d.ts +0 -67
- package/dist/StringSelectMenuKit-CJ0MzUZJ.d.ts +0 -67
- package/dist/UserSelectMenuKit-C_J-9RJs.d.ts +0 -67
- package/dist/app-CrjK9yWX.js +0 -0
- package/dist/app-process-AQ3Cbf6j.js +0 -68
- package/dist/app-process-AQ3Cbf6j.js.map +0 -1
- package/dist/build-BYMHMOl_.js +0 -173
- package/dist/build-BYMHMOl_.js.map +0 -1
- package/dist/commandkit-DabqpQ6v.js.map +0 -1
- package/dist/common-0Iw8ZeM6.js +0 -0
- package/dist/config-DbgXt6mf.d.ts +0 -16
- package/dist/constants-AH-9qJ89.js +0 -27
- package/dist/constants-BMWH2YUr.js.map +0 -1
- package/dist/dotprops-DvJUE8fw.js +0 -36
- package/dist/dotprops-DvJUE8fw.js.map +0 -1
- package/dist/env-8yY-6pbC.js.map +0 -1
- package/dist/error-codes-BiNRVMiV.d.ts +0 -54
- package/dist/feature-flags-BoBV4Dsj.js +0 -160
- package/dist/feature-flags-BoBV4Dsj.js.map +0 -1
- package/dist/init-CBb0StSB.js +0 -91
- package/dist/init-CBb0StSB.js.map +0 -1
- package/dist/init-DSYckXwx.d.ts +0 -13
- package/dist/resolve-file-url-DFtR8jRR.d.ts +0 -11
- package/dist/serde-D4H23l2F.d.ts +0 -12
- package/dist/serde-DHHwhltz.js +0 -97
- package/dist/serde-DHHwhltz.js.map +0 -1
- package/dist/utilities-CQUaua43.d.ts +0 -87
- package/dist/utils-Bf-3Eevb.js +0 -23
- package/dist/utils-Bf-3Eevb.js.map +0 -1
- package/dist/version-DC4j2ZwU.js +0 -18
- package/dist/version-DC4j2ZwU.js.map +0 -1
- package/dist/version-DggMfP_1.d.ts +0 -8
- /package/dist/{ILogger-B0q7p7L1.js → common-C2jAjX4U.js} +0 -0
- /package/dist/{index-B5F3AfVc.d.ts → index-BJfko-dP.d.ts} +0 -0
- /package/dist/{index-BLwMeReG.d.ts → index-CCggO_hw.d.ts} +0 -0
- /package/dist/{index-h64gcVNJ.d.ts → index-CLjpoGi1.d.ts} +0 -0
|
@@ -9,24 +9,24 @@
|
|
|
9
9
|
*/
|
|
10
10
|
interface MutexStorage {
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
* Attempts to acquire a lock for a given key
|
|
13
|
+
* @param key - The unique identifier for the mutex lock
|
|
14
|
+
* @param timeout - Optional timeout in milliseconds for the lock
|
|
15
|
+
* @param signal - Optional AbortSignal for cancelling the acquisition
|
|
16
|
+
* @returns Promise resolving to true if lock was acquired, false if timeout or already locked
|
|
17
|
+
*/
|
|
18
18
|
acquire(key: string, timeout?: number, signal?: AbortSignal): Promise<boolean>;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
* Releases the lock for a given key
|
|
21
|
+
* @param key - The unique identifier for the mutex lock
|
|
22
|
+
* @returns Promise that resolves when the lock is released
|
|
23
|
+
*/
|
|
24
24
|
release(key: string): Promise<void>;
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
* Checks if a lock is currently held for a given key
|
|
27
|
+
* @param key - The unique identifier for the mutex lock
|
|
28
|
+
* @returns Promise resolving to true if the lock is held, false otherwise
|
|
29
|
+
*/
|
|
30
30
|
isLocked(key: string): Promise<boolean>;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -45,24 +45,24 @@ interface MutexOptions {
|
|
|
45
45
|
declare class MemoryMutexStorage implements MutexStorage {
|
|
46
46
|
private readonly locks;
|
|
47
47
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
* Attempts to acquire a lock for a given key
|
|
49
|
+
* @param key - The unique identifier for the mutex lock
|
|
50
|
+
* @param timeout - Optional timeout in milliseconds for the lock
|
|
51
|
+
* @param signal - Optional AbortSignal for cancelling the acquisition
|
|
52
|
+
* @returns Promise resolving to true if lock was acquired, false if timeout or already locked
|
|
53
|
+
*/
|
|
54
54
|
acquire(key: string, timeout?: number, signal?: AbortSignal): Promise<boolean>;
|
|
55
55
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
* Releases the lock for a given key
|
|
57
|
+
* @param key - The unique identifier for the mutex lock
|
|
58
|
+
* @returns Promise that resolves when the lock is released
|
|
59
|
+
*/
|
|
60
60
|
release(key: string): Promise<void>;
|
|
61
61
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
* Checks if a lock is currently held for a given key
|
|
63
|
+
* @param key - The unique identifier for the mutex lock
|
|
64
|
+
* @returns Promise resolving to true if the lock is held, false otherwise
|
|
65
|
+
*/
|
|
66
66
|
isLocked(key: string): Promise<boolean>;
|
|
67
67
|
private generateHolderId;
|
|
68
68
|
private delay;
|
|
@@ -75,54 +75,54 @@ declare class Mutex {
|
|
|
75
75
|
private storage;
|
|
76
76
|
private readonly defaultTimeout;
|
|
77
77
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
* Creates a new mutex instance
|
|
79
|
+
* @param options - Configuration options for the mutex
|
|
80
|
+
*/
|
|
81
81
|
constructor(options?: MutexOptions);
|
|
82
82
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
* Sets the storage implementation for the mutex
|
|
84
|
+
* @param storage - The storage implementation to use
|
|
85
|
+
*/
|
|
86
86
|
setStorage(storage: MutexStorage): void;
|
|
87
87
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
* Gets the storage implementation for the mutex
|
|
89
|
+
* @returns The storage implementation
|
|
90
|
+
*/
|
|
91
91
|
getStorage(): MutexStorage;
|
|
92
92
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
* Acquires a lock for the given key
|
|
94
|
+
* @param key - The unique identifier for the mutex lock
|
|
95
|
+
* @param timeout - Optional timeout in milliseconds for lock acquisition
|
|
96
|
+
* @param signal - Optional AbortSignal for cancelling the acquisition
|
|
97
|
+
* @returns Promise resolving to true if lock was acquired, false if timeout
|
|
98
|
+
*/
|
|
99
99
|
acquire(key: string, timeout?: number, signal?: AbortSignal): Promise<boolean>;
|
|
100
100
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
* Releases the lock for the given key
|
|
102
|
+
* @param key - The unique identifier for the mutex lock
|
|
103
|
+
* @returns Promise that resolves when the lock is released
|
|
104
|
+
*/
|
|
105
105
|
release(key: string): Promise<void>;
|
|
106
106
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
* Checks if a lock is currently held for the given key
|
|
108
|
+
* @param key - The unique identifier for the mutex lock
|
|
109
|
+
* @returns Promise resolving to true if the lock is held, false otherwise
|
|
110
|
+
*/
|
|
111
111
|
isLocked(key: string): Promise<boolean>;
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
* Executes a function with exclusive access to the resource
|
|
114
|
+
* @param key - The unique identifier for the mutex lock
|
|
115
|
+
* @param fn - The function to execute with exclusive access
|
|
116
|
+
* @param timeout - Optional timeout in milliseconds for lock acquisition
|
|
117
|
+
* @param signal - Optional AbortSignal for cancelling the lock acquisition
|
|
118
|
+
* @returns Promise resolving to the result of the function execution
|
|
119
|
+
* @throws Error if lock acquisition fails or function execution fails
|
|
120
|
+
*/
|
|
121
121
|
withLock<T>(key: string, fn: () => Promise<T> | T, timeout?: number, signal?: AbortSignal): Promise<T>;
|
|
122
122
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
* Gets the current configuration of the mutex
|
|
124
|
+
* @returns Object containing the current timeout value
|
|
125
|
+
*/
|
|
126
126
|
getConfig(): Omit<MutexOptions, 'storage'>;
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
@@ -13,23 +13,23 @@ declare const DEFAULT_MAX_REQUESTS = 10;
|
|
|
13
13
|
*/
|
|
14
14
|
interface RateLimitStorage {
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
* Retrieves the current request count for a given key
|
|
17
|
+
* @param key - The unique identifier for the rate limit entry
|
|
18
|
+
* @returns Promise resolving to the current request count
|
|
19
|
+
*/
|
|
20
20
|
get(key: string): Promise<number>;
|
|
21
21
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
* Sets the request count for a given key
|
|
23
|
+
* @param key - The unique identifier for the rate limit entry
|
|
24
|
+
* @param value - The request count to store
|
|
25
|
+
* @returns Promise that resolves when the value is stored
|
|
26
|
+
*/
|
|
27
27
|
set(key: string, value: number): Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
* Deletes the rate limit entry for a given key
|
|
30
|
+
* @param key - The unique identifier for the rate limit entry
|
|
31
|
+
* @returns Promise that resolves when the entry is deleted
|
|
32
|
+
*/
|
|
33
33
|
delete(key: string): Promise<void>;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -50,23 +50,23 @@ interface RateLimitOptions {
|
|
|
50
50
|
declare class MemoryRateLimitStorage implements RateLimitStorage {
|
|
51
51
|
private readonly store;
|
|
52
52
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
* Retrieves the current request count for a given key
|
|
54
|
+
* @param key - The unique identifier for the rate limit entry
|
|
55
|
+
* @returns Promise resolving to the current request count or 0 if not found
|
|
56
|
+
*/
|
|
57
57
|
get(key: string): Promise<number>;
|
|
58
58
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
* Sets the request count for a given key
|
|
60
|
+
* @param key - The unique identifier for the rate limit entry
|
|
61
|
+
* @param value - The request count to store
|
|
62
|
+
* @returns Promise that resolves immediately
|
|
63
|
+
*/
|
|
64
64
|
set(key: string, value: number): Promise<void>;
|
|
65
65
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
* Deletes the rate limit entry for a given key
|
|
67
|
+
* @param key - The unique identifier for the rate limit entry
|
|
68
|
+
* @returns Promise that resolves immediately
|
|
69
|
+
*/
|
|
70
70
|
delete(key: string): Promise<void>;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
@@ -81,50 +81,50 @@ declare class RateLimiter {
|
|
|
81
81
|
private readonly lastReset;
|
|
82
82
|
private readonly resetInterval;
|
|
83
83
|
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
* Creates a new rate limiter instance
|
|
85
|
+
* @param maxRequests - Maximum number of requests allowed per interval (default: 10)
|
|
86
|
+
* @param interval - Time interval in milliseconds for the rate limit window (default: 60000)
|
|
87
|
+
* @param storage - Optional storage implementation (default: MemoryRateLimitStorage)
|
|
88
|
+
*/
|
|
89
89
|
constructor(maxRequests?: number, interval?: number, storage?: RateLimitStorage);
|
|
90
90
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
* Sets the storage implementation for the rate limiter
|
|
92
|
+
* @param storage - The storage implementation to use
|
|
93
|
+
*/
|
|
94
94
|
setStorage(storage: RateLimitStorage): void;
|
|
95
95
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
* Gets the storage implementation for the rate limiter
|
|
97
|
+
* @returns The storage implementation
|
|
98
|
+
*/
|
|
99
99
|
getStorage(): RateLimitStorage;
|
|
100
100
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
* Checks if a request is allowed for the given key and increments the counter if allowed
|
|
102
|
+
* @param key - The unique identifier for the rate limit entry
|
|
103
|
+
* @returns Promise resolving to true if the request is allowed, false if rate limited
|
|
104
|
+
*/
|
|
105
105
|
limit(key: string): Promise<boolean>;
|
|
106
106
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
* Gets the remaining requests allowed for a given key
|
|
108
|
+
* @param key - The unique identifier for the rate limit entry
|
|
109
|
+
* @returns Promise resolving to the number of remaining requests
|
|
110
|
+
*/
|
|
111
111
|
getRemaining(key: string): Promise<number>;
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
* Gets the time until the rate limit resets for a given key
|
|
114
|
+
* @param key - The unique identifier for the rate limit entry
|
|
115
|
+
* @returns Promise resolving to the time in milliseconds until reset, or 0 if no limit is active
|
|
116
|
+
*/
|
|
117
117
|
getResetTime(key: string): Promise<number>;
|
|
118
118
|
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
* Resets the rate limit for a given key
|
|
120
|
+
* @param key - The unique identifier for the rate limit entry
|
|
121
|
+
* @returns Promise that resolves when the reset is complete
|
|
122
|
+
*/
|
|
123
123
|
reset(key: string): Promise<void>;
|
|
124
124
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
* Gets the current configuration of the rate limiter
|
|
126
|
+
* @returns Object containing the current maxRequests and interval values
|
|
127
|
+
*/
|
|
128
128
|
getConfig(): Omit<RateLimitOptions, 'storage'>;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
@@ -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,iBACpC,AAAQ,UAA4B,IAAI,wBAAwB,EAChE;EAHiB;EACA;EACT;AAEN,OAAK,gBAAgB;;;;;;CAOvB,AAAO,WAAW,SAA2B;AAC3C,OAAK,UAAU;;;;;;CAOjB,AAAO,aAA+B;AACpC,SAAO,KAAK;;;;;;;CAQd,MAAa,MAAM,KAA+B;EAChD,MAAM,MAAM,KAAK,KAAK;AAKtB,MAHuB,OADL,KAAK,UAAU,IAAI,IAAI,IAAI,KAIxB,KAAK,eAAe;AACvC,SAAM,KAAK,QAAQ,OAAO,IAAI;AAC9B,QAAK,UAAU,IAAI,KAAK,IAAI;AAC5B,QAAK,OAAO,IAAI,KAAK,EAAE;;EAIzB,MAAM,eAAe,MAAM,KAAK,QAAQ,IAAI,IAAI;AAGhD,MAAI,gBAAgB,KAAK,YACvB,QAAO;EAIT,MAAM,WAAW,eAAe;AAChC,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS;AACrC,OAAK,OAAO,IAAI,KAAK,SAAS;AAE9B,SAAO;;;;;;;CAQT,MAAa,aAAa,KAA8B;EACtD,MAAM,eAAe,MAAM,KAAK,QAAQ,IAAI,IAAI;AAChD,SAAO,KAAK,IAAI,GAAG,KAAK,cAAc,aAAa;;;;;;;CAQrD,MAAa,aAAa,KAA8B;EACtD,MAAM,YAAY,KAAK,UAAU,IAAI,IAAI,IAAI;EAE7C,MAAM,iBADM,KAAK,KAAK,GACO;AAE7B,MAAI,kBAAkB,KAAK,cACzB,QAAO;AAGT,SAAO,KAAK,gBAAgB;;;;;;;CAQ9B,MAAa,MAAM,KAA4B;AAC7C,QAAM,KAAK,QAAQ,OAAO,IAAI;AAC9B,OAAK,OAAO,OAAO,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"}
|
|
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,AAAU,cAA6B,sBACvC,AAAU,WAA0B,iBACpC,AAAE,UAAkC,IAAE,wBAA0B,EAChE;EAHU;EACA;EACR;AAEA,OAAK,gBAAgB;;;;;;CAOvB,AAAO,WAAW,SAA2B;AAC3C,OAAK,UAAU;;;;;;CAOjB,AAAO,aAA+B;AACpC,SAAO,KAAK;;;;;;;CAQd,MAAa,MAAM,KAA+B;EAChD,MAAM,MAAM,KAAK,KAAK;AAKtB,MAHuB,OADL,KAAK,UAAU,IAAI,IAAI,IAAI,KAIxB,KAAK,eAAe;AACvC,SAAM,KAAK,QAAQ,OAAO,IAAI;AAC9B,QAAK,UAAU,IAAI,KAAK,IAAI;AAC5B,QAAK,OAAO,IAAI,KAAK,EAAE;;EAIzB,MAAM,eAAe,MAAM,KAAK,QAAQ,IAAI,IAAI;AAGhD,MAAI,gBAAgB,KAAK,YACvB,QAAO;EAIT,MAAM,WAAW,eAAe;AAChC,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS;AACrC,OAAK,OAAO,IAAI,KAAK,SAAS;AAE9B,SAAO;;;;;;;CAQT,MAAa,aAAa,KAA8B;EACtD,MAAM,eAAe,MAAM,KAAK,QAAQ,IAAI,IAAI;AAChD,SAAO,KAAK,IAAI,GAAG,KAAK,cAAc,aAAa;;;;;;;CAQrD,MAAa,aAAa,KAA8B;EACtD,MAAM,YAAY,KAAK,UAAU,IAAI,IAAI,IAAI;EAE7C,MAAM,iBADM,KAAK,KAAK,GACO;AAE7B,MAAI,kBAAkB,KAAK,cACzB,QAAO;AAGT,SAAO,KAAK,gBAAgB;;;;;;;CAQ9B,MAAa,MAAM,KAA4B;AAC7C,QAAM,KAAK,QAAQ,OAAO,IAAI;AAC9B,OAAK,OAAO,OAAO,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"}
|
|
@@ -9,30 +9,30 @@
|
|
|
9
9
|
*/
|
|
10
10
|
interface SemaphoreStorage {
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
* Attempts to acquire a permit for a given key
|
|
13
|
+
* @param key - The unique identifier for the semaphore
|
|
14
|
+
* @param timeout - Optional timeout in milliseconds for permit acquisition
|
|
15
|
+
* @param signal - Optional AbortSignal for cancelling the acquisition
|
|
16
|
+
* @returns Promise resolving to true if permit was acquired, false if timeout or no permits available
|
|
17
|
+
*/
|
|
18
18
|
acquire(key: string, timeout?: number, signal?: AbortSignal): Promise<boolean>;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
* Releases a permit for a given key
|
|
21
|
+
* @param key - The unique identifier for the semaphore
|
|
22
|
+
* @returns Promise that resolves when the permit is released
|
|
23
|
+
*/
|
|
24
24
|
release(key: string): Promise<void>;
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
* Gets the number of available permits for a given key
|
|
27
|
+
* @param key - The unique identifier for the semaphore
|
|
28
|
+
* @returns Promise resolving to the number of available permits
|
|
29
|
+
*/
|
|
30
30
|
getAvailablePermits(key: string): Promise<number>;
|
|
31
31
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
* Gets the total number of permits for a given key
|
|
33
|
+
* @param key - The unique identifier for the semaphore
|
|
34
|
+
* @returns Promise resolving to the total number of permits
|
|
35
|
+
*/
|
|
36
36
|
getTotalPermits(key: string): Promise<number>;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -53,36 +53,36 @@ interface SemaphoreOptions {
|
|
|
53
53
|
declare class MemorySemaphoreStorage implements SemaphoreStorage {
|
|
54
54
|
private readonly semaphores;
|
|
55
55
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
* Attempts to acquire a permit for a given key
|
|
57
|
+
* @param key - The unique identifier for the semaphore
|
|
58
|
+
* @param timeout - Optional timeout in milliseconds for permit acquisition
|
|
59
|
+
* @param signal - Optional AbortSignal for cancelling the acquisition
|
|
60
|
+
* @returns Promise resolving to true if permit was acquired, false if timeout or no permits available
|
|
61
|
+
*/
|
|
62
62
|
acquire(key: string, timeout?: number, signal?: AbortSignal): Promise<boolean>;
|
|
63
63
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
* Releases a permit for a given key
|
|
65
|
+
* @param key - The unique identifier for the semaphore
|
|
66
|
+
* @returns Promise that resolves when the permit is released
|
|
67
|
+
*/
|
|
68
68
|
release(key: string): Promise<void>;
|
|
69
69
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
* Gets the number of available permits for a given key
|
|
71
|
+
* @param key - The unique identifier for the semaphore
|
|
72
|
+
* @returns Promise resolving to the number of available permits
|
|
73
|
+
*/
|
|
74
74
|
getAvailablePermits(key: string): Promise<number>;
|
|
75
75
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
* Gets the total number of permits for a given key
|
|
77
|
+
* @param key - The unique identifier for the semaphore
|
|
78
|
+
* @returns Promise resolving to the total number of permits
|
|
79
|
+
*/
|
|
80
80
|
getTotalPermits(key: string): Promise<number>;
|
|
81
81
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
* Initializes a semaphore with the specified number of permits
|
|
83
|
+
* @param key - The unique identifier for the semaphore
|
|
84
|
+
* @param permits - The total number of permits to allocate
|
|
85
|
+
*/
|
|
86
86
|
initialize(key: string, permits: number): void;
|
|
87
87
|
private delay;
|
|
88
88
|
}
|
|
@@ -95,66 +95,66 @@ declare class Semaphore {
|
|
|
95
95
|
private readonly defaultPermits;
|
|
96
96
|
private readonly defaultTimeout;
|
|
97
97
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
* Creates a new semaphore instance
|
|
99
|
+
* @param options - Configuration options for the semaphore
|
|
100
|
+
*/
|
|
101
101
|
constructor(options?: SemaphoreOptions);
|
|
102
102
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
* Sets the storage implementation for the semaphore
|
|
104
|
+
* @param storage - The storage implementation to use
|
|
105
|
+
*/
|
|
106
106
|
setStorage(storage: SemaphoreStorage): void;
|
|
107
107
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
* Gets the storage implementation for the semaphore
|
|
109
|
+
* @returns The storage implementation
|
|
110
|
+
*/
|
|
111
111
|
getStorage(): SemaphoreStorage;
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
* Acquires a permit for the given key
|
|
114
|
+
* @param key - The unique identifier for the semaphore
|
|
115
|
+
* @param timeout - Optional timeout in milliseconds for permit acquisition
|
|
116
|
+
* @param signal - Optional AbortSignal for cancelling the acquisition
|
|
117
|
+
* @returns Promise resolving to true if permit was acquired, false if timeout
|
|
118
|
+
*/
|
|
119
119
|
acquire(key: string, timeout?: number, signal?: AbortSignal): Promise<boolean>;
|
|
120
120
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
* Releases a permit for the given key
|
|
122
|
+
* @param key - The unique identifier for the semaphore
|
|
123
|
+
* @returns Promise that resolves when the permit is released
|
|
124
|
+
*/
|
|
125
125
|
release(key: string): Promise<void>;
|
|
126
126
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
* Gets the number of available permits for the given key
|
|
128
|
+
* @param key - The unique identifier for the semaphore
|
|
129
|
+
* @returns Promise resolving to the number of available permits
|
|
130
|
+
*/
|
|
131
131
|
getAvailablePermits(key: string): Promise<number>;
|
|
132
132
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
* Gets the total number of permits for the given key
|
|
134
|
+
* @param key - The unique identifier for the semaphore
|
|
135
|
+
* @returns Promise resolving to the total number of permits
|
|
136
|
+
*/
|
|
137
137
|
getTotalPermits(key: string): Promise<number>;
|
|
138
138
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
* Gets the number of acquired permits for the given key
|
|
140
|
+
* @param key - The unique identifier for the semaphore
|
|
141
|
+
* @returns Promise resolving to the number of acquired permits
|
|
142
|
+
*/
|
|
143
143
|
getAcquiredPermits(key: string): Promise<number>;
|
|
144
144
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
* Executes a function with a permit from the semaphore
|
|
146
|
+
* @param key - The unique identifier for the semaphore
|
|
147
|
+
* @param fn - The function to execute with a permit
|
|
148
|
+
* @param timeout - Optional timeout in milliseconds for permit acquisition
|
|
149
|
+
* @param signal - Optional AbortSignal for cancelling the permit acquisition
|
|
150
|
+
* @returns Promise resolving to the result of the function execution
|
|
151
|
+
* @throws Error if permit acquisition fails or function execution fails
|
|
152
|
+
*/
|
|
153
153
|
withPermit<T>(key: string, fn: () => Promise<T> | T, timeout?: number, signal?: AbortSignal): Promise<T>;
|
|
154
154
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
* Gets the current configuration of the semaphore
|
|
156
|
+
* @returns Object containing the current permits and timeout values
|
|
157
|
+
*/
|
|
158
158
|
getConfig(): Omit<SemaphoreOptions, 'storage'>;
|
|
159
159
|
}
|
|
160
160
|
/**
|