commandkit 1.2.0-dev.20251007125144 → 1.2.0-dev.20251008125155
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/{MessageCommandParser-Dl0xxtdr.js → MessageCommandParser-D4NQu2od.js} +52 -53
- package/dist/{MessageCommandParser-Dl0xxtdr.js.map → MessageCommandParser-D4NQu2od.js.map} +1 -1
- package/dist/analytics/analytics-engine.js +4 -4
- package/dist/analytics/utils.js +4 -4
- package/dist/app/commands/AppCommandRunner.js +4 -4
- package/dist/app/commands/Context.js +4 -4
- package/dist/app/commands/MessageCommandParser.js +1 -1
- package/dist/app/handlers/AppCommandHandler.js +4 -4
- package/dist/app/handlers/AppEventsHandler.js +4 -4
- package/dist/app/index.js +4 -4
- package/dist/app/middlewares/permissions.js +4 -4
- package/dist/app/register/CommandRegistrar.js +4 -4
- package/dist/{app-process-cj2vF12T.js → app-process-BZ7sTCzv.js} +2 -2
- package/dist/{app-process-cj2vF12T.js.map → app-process-BZ7sTCzv.js.map} +1 -1
- package/dist/{build-CRUCqIzm.js → build-DWG0_HV5.js} +6 -7
- package/dist/{build-CRUCqIzm.js.map → build-DWG0_HV5.js.map} +1 -1
- package/dist/cli/app-process.js +3 -3
- package/dist/cli/build.js +6 -6
- package/dist/cli/common.js +2 -2
- package/dist/cli/development.js +7 -7
- package/dist/cli/generators.js +2 -2
- package/dist/cli/information.js +1 -1
- package/dist/cli/init.js +5 -5
- package/dist/cli/production.js +8 -9
- package/dist/cli/production.js.map +1 -1
- package/dist/cli/type-checker.js +3 -3
- package/dist/{commandkit-v0hBWgPh.js → commandkit-D_X1yJyt.js} +10 -19
- package/dist/{commandkit-v0hBWgPh.js.map → commandkit-D_X1yJyt.js.map} +1 -1
- package/dist/commandkit.js +4 -4
- package/dist/{common-CrqwC-sx.js → common-BkRtx9ij.js} +3 -4
- package/dist/{common-CrqwC-sx.js.map → common-BkRtx9ij.js.map} +1 -1
- package/dist/components/index.js +4 -4
- package/dist/components/v1/button/Button.js +4 -4
- package/dist/components/v1/button/ButtonKit.js +4 -4
- package/dist/components/v1/modal/Modal.js +4 -4
- package/dist/components/v1/modal/ModalKit.js +4 -4
- package/dist/components/v1/select-menu/ChannelSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/MentionableSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/RoleSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/SelectMenu.js +4 -4
- package/dist/components/v1/select-menu/StringSelectMenuKit.js +4 -4
- package/dist/components/v1/select-menu/UserSelectMenuKit.js +4 -4
- package/dist/config/config.js +4 -4
- package/dist/config/default.js +4 -4
- package/dist/config/loader.js +4 -4
- package/dist/context/async-context.js +4 -4
- package/dist/context/environment.js +4 -4
- package/dist/{feature-flags-DU3dxV2M.js → feature-flags-B3KR7vGo.js} +2 -2
- package/dist/{feature-flags-DU3dxV2M.js.map → feature-flags-B3KR7vGo.js.map} +1 -1
- package/dist/flags/feature-flags.js +5 -5
- package/dist/index.js +7 -7
- package/dist/{init-ZnKLKLM_.js → init-PfRfhy7q.js} +9 -13
- package/dist/{init-ZnKLKLM_.js.map → init-PfRfhy7q.js.map} +1 -1
- package/dist/kv/kv.js +2 -4
- package/dist/kv/kv.js.map +1 -1
- package/dist/logger/DefaultLogger.js +4 -4
- package/dist/logger/Logger.js +4 -4
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +4 -4
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +4 -4
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +4 -4
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +4 -4
- package/dist/{type-checker-ocNSZh0W.js → type-checker-Co98mRrK.js} +2 -2
- package/dist/{type-checker-ocNSZh0W.js.map → type-checker-Co98mRrK.js.map} +1 -1
- package/dist/{types-package-BWArjyBF.js → types-package-D2_jGQvq.js} +2 -3
- package/dist/{types-package-BWArjyBF.js.map → types-package-D2_jGQvq.js.map} +1 -1
- package/dist/utils/dev-hooks.js +4 -4
- package/dist/utils/types-package.js +1 -1
- 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.js +4 -4
- package/dist/{version-BmB3JZPy.js → version-CK3uSO6m.js} +2 -2
- package/dist/{version-BmB3JZPy.js.map → version-CK3uSO6m.js.map} +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags-DU3dxV2M.js","names":[],"sources":["../src/flags/feature-flags.ts"],"sourcesContent":["import { getCommandKit, getContext } from '../context/async-context';\nimport { eventWorkerContext } from '../app/events/EventWorkerContext';\nimport { ParsedEvent } from '../app/router';\nimport { CommandKit } from '../commandkit';\nimport {\n AutocompleteInteraction,\n ChatInputCommandInteraction,\n Client,\n ClientEvents,\n ContextMenuCommandInteraction,\n Guild,\n Message,\n TextBasedChannel,\n} from 'discord.js';\nimport { LoadedCommand } from '../app';\nimport { defer, JsonSerialize } from '../utils/utilities';\nimport { AnalyticsEvents } from '../analytics/constants';\nimport { FlagProvider, FlagConfiguration } from './FlagProvider';\nimport { Logger } from '../logger/Logger';\n\n// Global flag provider\nlet flagProvider: FlagProvider | null = null;\n\n/**\n * Set the global flag provider for all feature flags\n */\nexport function setFlagProvider(provider: FlagProvider): void {\n flagProvider = provider;\n}\n\n/**\n * @private\n */\nexport type MaybePromise<T> = T | Promise<T>;\n\n/**\n * Function type for identifying entities in the context of feature flags.\n * This function should return an object representing the entity that will be used\n * to evaluate the feature flag.\n * It can be synchronous or asynchronous.\n */\nexport type IdentifyFunction<R> = (\n context: EvaluationContext,\n) => MaybePromise<R>;\n\n/**\n * Function type for deciding the outcome of a feature flag based on the provided entities.\n * This function receives an object containing the entities and optionally the provider configuration,\n * and should return the result of the decision.\n * It can be synchronous or asynchronous.\n */\nexport type DecideFunction<E, R> = (data: {\n entities: E;\n provider?: FlagConfiguration | null;\n}) => MaybePromise<R>;\n\n/**\n * Definition for a feature flag, including its key, description, identify function,\n * and decide function.\n * The identify function is used to determine the entities that will be evaluated\n * against the feature flag, while the decide function contains the logic for\n * determining the outcome of the flag based on those entities.\n */\nexport interface FeatureFlagDefinition<R, Entity> {\n /**\n * Unique key for the feature flag.\n * Should be a string that identifies the flag.\n */\n key: string;\n /**\n * Optional description of the feature flag.\n * This can be used for documentation or debugging purposes.\n */\n description?: string;\n /**\n * Optional flag to enable integration with an external flag provider.\n * If true, the flag will use the global flag provider to determine its state.\n * Default: false\n */\n identify?: IdentifyFunction<Entity>;\n /**\n * Function to decide the outcome of the feature flag.\n * This function receives the identified entities and should return the result of the decision.\n */\n decide: DecideFunction<Entity, R>;\n /**\n * Whether to disable analytics tracking for this flag.\n * Default: false\n */\n disableAnalytics?: boolean;\n}\n\n/**\n * Context for evaluating command flags in CommandKit.\n */\nexport interface CommandFlagContext {\n /**\n * The Discord client instance.\n * This is the main entry point for interacting with the Discord API.\n */\n client: Client<true>;\n /**\n * The CommandKit instance, which provides access to the command framework.\n * This includes commands, events, and other features of CommandKit.\n */\n commandkit: CommandKit;\n /**\n * The command context, which includes information about the command being executed.\n * This can include the interaction, message, guild, channel, and the loaded command.\n */\n command: {\n /**\n * The interaction object if the command was invoked via an interaction.\n * This can be a ChatInputCommandInteraction, AutocompleteInteraction, or ContextMenuCommandInteraction.\n */\n interaction?:\n | ChatInputCommandInteraction\n | AutocompleteInteraction\n | ContextMenuCommandInteraction;\n /**\n * The message object if the command was invoked via a message.\n */\n message?: Message;\n /**\n * The guild where the command was invoked, if applicable.\n * This will be null for commands invoked in DMs.\n */\n guild: Guild | null;\n /**\n * The channel where the command was invoked.\n * This can be a text channel, DM channel, or any other type of text-based channel.\n */\n channel: TextBasedChannel | null;\n /**\n * The loaded command instance that is being executed.\n * This contains the command's metadata and logic.\n */\n command: LoadedCommand;\n };\n /**\n * The event context is null for command flags, as they are not tied to a specific event.\n * This is used to differentiate between command and event flags.\n */\n event: null;\n}\n\n/**\n * Context for evaluating event flags in CommandKit.\n */\nexport interface EventFlagContext {\n /**\n * The Discord client instance.\n * This is the main entry point for interacting with the Discord API.\n */\n client: Client<true>;\n /**\n * The CommandKit instance, which provides access to the command framework.\n * This includes commands, events, and other features of CommandKit.\n */\n commandkit: CommandKit;\n /**\n * The event context, which includes information about the event being processed.\n * This can include the parsed event data, the event name, and the namespace if applicable.\n */\n event: {\n /**\n * The parsed event data, which contains the raw data from the event.\n * This can include information like user IDs, channel IDs, and other relevant data.\n */\n data: ParsedEvent;\n /**\n * The name of the event being processed.\n * This is the string identifier for the event, such as 'messageCreate' or 'guildMemberAdd'.\n */\n event: string;\n /**\n * The namespace of the event, if applicable.\n * This can be used to group related events or commands together.\n * It is null if the event does not belong to a specific namespace.\n */\n namespace: string | null;\n /**\n * The arguments passed to the event handler.\n * This is an array of arguments that were passed when the event was triggered.\n * It can be used to access specific data related to the event.\n */\n arguments: any[];\n /**\n * A function to retrieve the arguments for a specific event type.\n * This allows for type-safe access to the arguments based on the event name.\n * @param event - The name of the event to retrieve arguments for.\n */\n argumentsAs<E extends keyof ClientEvents>(event: E): ClientEvents[E];\n };\n /**\n * The command context is null for event flags, as they are not tied to a specific command.\n * This is used to differentiate between command and event flags.\n */\n command: null;\n}\n\n/**\n * Combined context type for feature flag evaluation.\n */\nexport type EvaluationContext = CommandFlagContext | EventFlagContext;\n\n/**\n * Function type for custom evaluation of feature flags.\n * This function can be used to provide a custom evaluation context for the flag.\n * It should return an object representing the entities to be evaluated.\n */\nexport type CustomEvaluationFunction<E> = () => MaybePromise<E>;\n\n/**\n * Context for custom evaluation of feature flags.\n * This allows for more flexible evaluation based on custom logic or external data.\n * The identify function can be a direct object or a function that returns the entities.\n */\nexport type CustomEvaluationContext<E> = {\n /**\n * Optional function to identify the entities for evaluation.\n * This can be a function that returns the entities based on the current context.\n */\n identify: E | CustomEvaluationFunction<E>;\n};\n\nexport interface FlagRunner<E, R> {\n /**\n * Execute the feature flag evaluation with the provided entities.\n * This method will run the identify and decide functions to determine the flag's outcome.\n * @param res - Optional entities to use for evaluation. If not provided, it will call the identify function.\n * @returns A promise that resolves to the result of the feature flag evaluation.\n */\n (): Promise<R>;\n /**\n * Run the feature flag evaluation with a custom context.\n * This allows for more flexible evaluation based on custom logic or external data.\n * @param context - The custom evaluation context containing the identify function or object.\n * @returns A promise that resolves to the result of the feature flag evaluation.\n */\n run(context: CustomEvaluationContext<E>): Promise<R>;\n}\n\n/**\n * Class representing a feature flag in CommandKit.\n */\nexport class FeatureFlag<R, T> {\n private commandkit: CommandKit;\n\n /**\n * Create a new feature flag.\n * @param options - The options for the feature flag.\n */\n public constructor(public readonly options: FeatureFlagDefinition<R, T>) {\n this.commandkit = getCommandKit(true);\n const FlagStore = this.commandkit.flags;\n\n if (FlagStore.has(options.key)) {\n throw new Error(`Feature flag with key \"${options.key}\" already exists.`);\n }\n\n FlagStore.set(options.key, this);\n }\n\n private getContext(): EvaluationContext {\n const env = getContext();\n\n if (env?.context) {\n const {\n client,\n commandkit,\n interaction,\n message,\n guild,\n channel,\n command,\n } = env.context;\n\n return {\n client: client as Client<true>,\n commandkit,\n command: {\n interaction,\n message,\n guild,\n channel,\n command,\n },\n event: null,\n };\n }\n\n const eventCtx = eventWorkerContext.getStore();\n\n if (eventCtx) {\n const { commandkit, data, event, namespace } = eventCtx;\n\n return {\n client: commandkit.client as Client<true>,\n commandkit,\n event: {\n data,\n event,\n namespace,\n arguments: eventCtx.arguments,\n argumentsAs: (eventName) => {\n const args = eventCtx.arguments as ClientEvents[typeof eventName];\n return args;\n },\n },\n command: null,\n };\n }\n\n throw new Error(\n 'Could not determine the execution context. Feature flags may only be used inside a command or event.',\n );\n }\n\n /**\n * Execute the feature flag evaluation.\n * @param res - Optional entities to use for evaluation. If not provided, it will call the identify function.\n * @returns A promise that resolves to the result of the feature flag evaluation.\n */\n public async execute(res?: T): Promise<R> {\n const { decide, identify, disableAnalytics } = this.options;\n\n const identificationStart = performance.now();\n const entities =\n res ??\n (await (async () => {\n const ctx = this.getContext();\n return (await identify?.(ctx)) ?? ({} as T);\n })());\n const identificationTime = performance.now() - identificationStart;\n\n // Get provider configuration if global provider is available\n let providerConfig: FlagConfiguration | null = null;\n if (flagProvider) {\n try {\n providerConfig = await flagProvider.getFlag(this.options.key, entities);\n\n // If provider says flag is disabled, return early with default behavior\n if (providerConfig && !providerConfig.enabled) {\n // For boolean flags, return false; for others, let decide function handle it\n if (typeof decide === 'function') {\n const decisionResult = await decide({\n entities,\n provider: providerConfig,\n });\n return decisionResult as R;\n }\n }\n } catch (error) {\n Logger.error`Error fetching flag provider configuration for \"${this.options.key}\": ${error}`;\n // continue with local decision if provider fails\n }\n }\n\n const decisionStart = performance.now();\n const decisionResult = await decide({\n entities,\n provider: providerConfig,\n });\n const decisionTime = performance.now() - decisionStart;\n\n // Skip analytics if disabled\n if (!disableAnalytics) {\n defer(async () => {\n await this.commandkit.analytics.track({\n name: AnalyticsEvents.FEATURE_FLAG_METRICS,\n data: {\n flag: this.options.key,\n identificationTime: identificationTime.toFixed(2),\n decisionTime: decisionTime.toFixed(2),\n usedProvider: flagProvider !== null,\n providerEnabled: providerConfig?.enabled ?? null,\n },\n });\n });\n\n defer(async () => {\n await this.commandkit.analytics.track({\n name: AnalyticsEvents.FEATURE_FLAG_DECISION,\n id:\n entities &&\n typeof entities === 'object' &&\n 'id' in entities &&\n typeof entities.id === 'string'\n ? entities.id\n : undefined,\n data: {\n flag: this.options.key,\n decision: JsonSerialize(decisionResult, 'unknown'),\n providerUsed: flagProvider !== null,\n },\n });\n });\n }\n\n return decisionResult as R;\n }\n}\n\n/**\n * Create a new feature flag.\n * @param options - The options for the feature flag.\n * @returns A new instance of the FeatureFlag class.\n */\nexport function flag<Returns = boolean, Entity = Record<any, any>>(\n options: FeatureFlagDefinition<Returns, Entity>,\n): FlagRunner<Entity, Returns> {\n const flag = new FeatureFlag<Returns, Entity>(options);\n const runner = flag.execute.bind(flag, undefined) as FlagRunner<\n Entity,\n Returns\n >;\n\n runner.run = async function (ctx) {\n if (!ctx?.identify) {\n throw new Error(\n 'Custom evaluation context must have an identify function or object.',\n );\n }\n\n const context = (\n typeof ctx === 'function'\n ? await (ctx as CustomEvaluationFunction<Entity>)()\n : ctx\n ) as Entity;\n\n const decisionResult = await flag.execute(context);\n\n return decisionResult;\n };\n\n return runner;\n}\n"],"mappings":";;;;;AAqBA,IAAI,eAAoC;;;;AAKxC,SAAgB,gBAAgB,UAA8B;AAC5D,gBAAe;;;;;AA2NjB,IAAa,cAAb,MAA+B;CAC7B,AAAQ;;;;;CAMR,AAAO,YAAY,AAAgB,SAAsC;EAAtC;AACjC,OAAK,aAAa,iCAAc,KAAK;EACrC,MAAM,YAAY,KAAK,WAAW;AAElC,MAAI,UAAU,IAAI,QAAQ,IAAI,CAC5B,OAAM,IAAI,MAAM,0BAA0B,QAAQ,IAAI,mBAAmB;AAG3E,YAAU,IAAI,QAAQ,KAAK,KAAK;;CAGlC,AAAQ,aAAgC;EACtC,MAAM,MAAM,+BAAY;AAExB,gDAAI,IAAK,SAAS;GAChB,MAAM,EACJ,QACA,YACA,aACA,SACA,OACA,SACA,YACE,IAAI;AAER,UAAO;IACG;IACR;IACA,SAAS;KACP;KACA;KACA;KACA;KACA;KACD;IACD,OAAO;IACR;;EAGH,MAAM,WAAW,8CAAmB,UAAU;AAE9C,MAAI,UAAU;GACZ,MAAM,EAAE,YAAY,MAAM,OAAO,cAAc;AAE/C,UAAO;IACL,QAAQ,WAAW;IACnB;IACA,OAAO;KACL;KACA;KACA;KACA,WAAW,SAAS;KACpB,cAAc,cAAc;AAE1B,aADa,SAAS;;KAGzB;IACD,SAAS;IACV;;AAGH,QAAM,IAAI,M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;KACF;;AAGJ,SAAO;;;;;;;;AASX,SAAgB,KAChB,SAC8B;CAC5B,MAAM,SAAO,IAAI,YAA6B,QAAQ;CACtD,MAAM,SAAS,OAAK,QAAQ,KAAK,QAAM,OAAU;AAKjD,QAAO,MAAM,eAAgB,KAAK;AAChC,MAAI,4CAAC,IAAK,UACR,OAAM,IAAI,MACR,sEACD;EAGH,MAAM,UACN,OAAO,QAAQ,aACf,MAAO,KAA0C,GACjD;AAKA,SAFuB,MAAM,OAAK,QAAQ,QAAQ;;AAKpD,QAAO"}
|
|
1
|
+
{"version":3,"file":"feature-flags-B3KR7vGo.js","names":[],"sources":["../src/flags/feature-flags.ts"],"sourcesContent":["import { getCommandKit, getContext } from '../context/async-context';\nimport { eventWorkerContext } from '../app/events/EventWorkerContext';\nimport { ParsedEvent } from '../app/router';\nimport { CommandKit } from '../commandkit';\nimport {\n AutocompleteInteraction,\n ChatInputCommandInteraction,\n Client,\n ClientEvents,\n ContextMenuCommandInteraction,\n Guild,\n Message,\n TextBasedChannel,\n} from 'discord.js';\nimport { LoadedCommand } from '../app';\nimport { defer, JsonSerialize } from '../utils/utilities';\nimport { AnalyticsEvents } from '../analytics/constants';\nimport { FlagProvider, FlagConfiguration } from './FlagProvider';\nimport { Logger } from '../logger/Logger';\n\n// Global flag provider\nlet flagProvider: FlagProvider | null = null;\n\n/**\n * Set the global flag provider for all feature flags\n */\nexport function setFlagProvider(provider: FlagProvider): void {\n flagProvider = provider;\n}\n\n/**\n * @private\n */\nexport type MaybePromise<T> = T | Promise<T>;\n\n/**\n * Function type for identifying entities in the context of feature flags.\n * This function should return an object representing the entity that will be used\n * to evaluate the feature flag.\n * It can be synchronous or asynchronous.\n */\nexport type IdentifyFunction<R> = (\n context: EvaluationContext,\n) => MaybePromise<R>;\n\n/**\n * Function type for deciding the outcome of a feature flag based on the provided entities.\n * This function receives an object containing the entities and optionally the provider configuration,\n * and should return the result of the decision.\n * It can be synchronous or asynchronous.\n */\nexport type DecideFunction<E, R> = (data: {\n entities: E;\n provider?: FlagConfiguration | null;\n}) => MaybePromise<R>;\n\n/**\n * Definition for a feature flag, including its key, description, identify function,\n * and decide function.\n * The identify function is used to determine the entities that will be evaluated\n * against the feature flag, while the decide function contains the logic for\n * determining the outcome of the flag based on those entities.\n */\nexport interface FeatureFlagDefinition<R, Entity> {\n /**\n * Unique key for the feature flag.\n * Should be a string that identifies the flag.\n */\n key: string;\n /**\n * Optional description of the feature flag.\n * This can be used for documentation or debugging purposes.\n */\n description?: string;\n /**\n * Optional flag to enable integration with an external flag provider.\n * If true, the flag will use the global flag provider to determine its state.\n * Default: false\n */\n identify?: IdentifyFunction<Entity>;\n /**\n * Function to decide the outcome of the feature flag.\n * This function receives the identified entities and should return the result of the decision.\n */\n decide: DecideFunction<Entity, R>;\n /**\n * Whether to disable analytics tracking for this flag.\n * Default: false\n */\n disableAnalytics?: boolean;\n}\n\n/**\n * Context for evaluating command flags in CommandKit.\n */\nexport interface CommandFlagContext {\n /**\n * The Discord client instance.\n * This is the main entry point for interacting with the Discord API.\n */\n client: Client<true>;\n /**\n * The CommandKit instance, which provides access to the command framework.\n * This includes commands, events, and other features of CommandKit.\n */\n commandkit: CommandKit;\n /**\n * The command context, which includes information about the command being executed.\n * This can include the interaction, message, guild, channel, and the loaded command.\n */\n command: {\n /**\n * The interaction object if the command was invoked via an interaction.\n * This can be a ChatInputCommandInteraction, AutocompleteInteraction, or ContextMenuCommandInteraction.\n */\n interaction?:\n | ChatInputCommandInteraction\n | AutocompleteInteraction\n | ContextMenuCommandInteraction;\n /**\n * The message object if the command was invoked via a message.\n */\n message?: Message;\n /**\n * The guild where the command was invoked, if applicable.\n * This will be null for commands invoked in DMs.\n */\n guild: Guild | null;\n /**\n * The channel where the command was invoked.\n * This can be a text channel, DM channel, or any other type of text-based channel.\n */\n channel: TextBasedChannel | null;\n /**\n * The loaded command instance that is being executed.\n * This contains the command's metadata and logic.\n */\n command: LoadedCommand;\n };\n /**\n * The event context is null for command flags, as they are not tied to a specific event.\n * This is used to differentiate between command and event flags.\n */\n event: null;\n}\n\n/**\n * Context for evaluating event flags in CommandKit.\n */\nexport interface EventFlagContext {\n /**\n * The Discord client instance.\n * This is the main entry point for interacting with the Discord API.\n */\n client: Client<true>;\n /**\n * The CommandKit instance, which provides access to the command framework.\n * This includes commands, events, and other features of CommandKit.\n */\n commandkit: CommandKit;\n /**\n * The event context, which includes information about the event being processed.\n * This can include the parsed event data, the event name, and the namespace if applicable.\n */\n event: {\n /**\n * The parsed event data, which contains the raw data from the event.\n * This can include information like user IDs, channel IDs, and other relevant data.\n */\n data: ParsedEvent;\n /**\n * The name of the event being processed.\n * This is the string identifier for the event, such as 'messageCreate' or 'guildMemberAdd'.\n */\n event: string;\n /**\n * The namespace of the event, if applicable.\n * This can be used to group related events or commands together.\n * It is null if the event does not belong to a specific namespace.\n */\n namespace: string | null;\n /**\n * The arguments passed to the event handler.\n * This is an array of arguments that were passed when the event was triggered.\n * It can be used to access specific data related to the event.\n */\n arguments: any[];\n /**\n * A function to retrieve the arguments for a specific event type.\n * This allows for type-safe access to the arguments based on the event name.\n * @param event - The name of the event to retrieve arguments for.\n */\n argumentsAs<E extends keyof ClientEvents>(event: E): ClientEvents[E];\n };\n /**\n * The command context is null for event flags, as they are not tied to a specific command.\n * This is used to differentiate between command and event flags.\n */\n command: null;\n}\n\n/**\n * Combined context type for feature flag evaluation.\n */\nexport type EvaluationContext = CommandFlagContext | EventFlagContext;\n\n/**\n * Function type for custom evaluation of feature flags.\n * This function can be used to provide a custom evaluation context for the flag.\n * It should return an object representing the entities to be evaluated.\n */\nexport type CustomEvaluationFunction<E> = () => MaybePromise<E>;\n\n/**\n * Context for custom evaluation of feature flags.\n * This allows for more flexible evaluation based on custom logic or external data.\n * The identify function can be a direct object or a function that returns the entities.\n */\nexport type CustomEvaluationContext<E> = {\n /**\n * Optional function to identify the entities for evaluation.\n * This can be a function that returns the entities based on the current context.\n */\n identify: E | CustomEvaluationFunction<E>;\n};\n\nexport interface FlagRunner<E, R> {\n /**\n * Execute the feature flag evaluation with the provided entities.\n * This method will run the identify and decide functions to determine the flag's outcome.\n * @param res - Optional entities to use for evaluation. If not provided, it will call the identify function.\n * @returns A promise that resolves to the result of the feature flag evaluation.\n */\n (): Promise<R>;\n /**\n * Run the feature flag evaluation with a custom context.\n * This allows for more flexible evaluation based on custom logic or external data.\n * @param context - The custom evaluation context containing the identify function or object.\n * @returns A promise that resolves to the result of the feature flag evaluation.\n */\n run(context: CustomEvaluationContext<E>): Promise<R>;\n}\n\n/**\n * Class representing a feature flag in CommandKit.\n */\nexport class FeatureFlag<R, T> {\n private commandkit: CommandKit;\n\n /**\n * Create a new feature flag.\n * @param options - The options for the feature flag.\n */\n public constructor(public readonly options: FeatureFlagDefinition<R, T>) {\n this.commandkit = getCommandKit(true);\n const FlagStore = this.commandkit.flags;\n\n if (FlagStore.has(options.key)) {\n throw new Error(`Feature flag with key \"${options.key}\" already exists.`);\n }\n\n FlagStore.set(options.key, this);\n }\n\n private getContext(): EvaluationContext {\n const env = getContext();\n\n if (env?.context) {\n const {\n client,\n commandkit,\n interaction,\n message,\n guild,\n channel,\n command,\n } = env.context;\n\n return {\n client: client as Client<true>,\n commandkit,\n command: {\n interaction,\n message,\n guild,\n channel,\n command,\n },\n event: null,\n };\n }\n\n const eventCtx = eventWorkerContext.getStore();\n\n if (eventCtx) {\n const { commandkit, data, event, namespace } = eventCtx;\n\n return {\n client: commandkit.client as Client<true>,\n commandkit,\n event: {\n data,\n event,\n namespace,\n arguments: eventCtx.arguments,\n argumentsAs: (eventName) => {\n const args = eventCtx.arguments as ClientEvents[typeof eventName];\n return args;\n },\n },\n command: null,\n };\n }\n\n throw new Error(\n 'Could not determine the execution context. Feature flags may only be used inside a command or event.',\n );\n }\n\n /**\n * Execute the feature flag evaluation.\n * @param res - Optional entities to use for evaluation. If not provided, it will call the identify function.\n * @returns A promise that resolves to the result of the feature flag evaluation.\n */\n public async execute(res?: T): Promise<R> {\n const { decide, identify, disableAnalytics } = this.options;\n\n const identificationStart = performance.now();\n const entities =\n res ??\n (await (async () => {\n const ctx = this.getContext();\n return (await identify?.(ctx)) ?? ({} as T);\n })());\n const identificationTime = performance.now() - identificationStart;\n\n // Get provider configuration if global provider is available\n let providerConfig: FlagConfiguration | null = null;\n if (flagProvider) {\n try {\n providerConfig = await flagProvider.getFlag(this.options.key, entities);\n\n // If provider says flag is disabled, return early with default behavior\n if (providerConfig && !providerConfig.enabled) {\n // For boolean flags, return false; for others, let decide function handle it\n if (typeof decide === 'function') {\n const decisionResult = await decide({\n entities,\n provider: providerConfig,\n });\n return decisionResult as R;\n }\n }\n } catch (error) {\n Logger.error`Error fetching flag provider configuration for \"${this.options.key}\": ${error}`;\n // continue with local decision if provider fails\n }\n }\n\n const decisionStart = performance.now();\n const decisionResult = await decide({\n entities,\n provider: providerConfig,\n });\n const decisionTime = performance.now() - decisionStart;\n\n // Skip analytics if disabled\n if (!disableAnalytics) {\n defer(async () => {\n await this.commandkit.analytics.track({\n name: AnalyticsEvents.FEATURE_FLAG_METRICS,\n data: {\n flag: this.options.key,\n identificationTime: identificationTime.toFixed(2),\n decisionTime: decisionTime.toFixed(2),\n usedProvider: flagProvider !== null,\n providerEnabled: providerConfig?.enabled ?? null,\n },\n });\n });\n\n defer(async () => {\n await this.commandkit.analytics.track({\n name: AnalyticsEvents.FEATURE_FLAG_DECISION,\n id:\n entities &&\n typeof entities === 'object' &&\n 'id' in entities &&\n typeof entities.id === 'string'\n ? entities.id\n : undefined,\n data: {\n flag: this.options.key,\n decision: JsonSerialize(decisionResult, 'unknown'),\n providerUsed: flagProvider !== null,\n },\n });\n });\n }\n\n return decisionResult as R;\n }\n}\n\n/**\n * Create a new feature flag.\n * @param options - The options for the feature flag.\n * @returns A new instance of the FeatureFlag class.\n */\nexport function flag<Returns = boolean, Entity = Record<any, any>>(\n options: FeatureFlagDefinition<Returns, Entity>,\n): FlagRunner<Entity, Returns> {\n const flag = new FeatureFlag<Returns, Entity>(options);\n const runner = flag.execute.bind(flag, undefined) as FlagRunner<\n Entity,\n Returns\n >;\n\n runner.run = async function (ctx) {\n if (!ctx?.identify) {\n throw new Error(\n 'Custom evaluation context must have an identify function or object.',\n );\n }\n\n const context = (\n typeof ctx === 'function'\n ? await (ctx as CustomEvaluationFunction<Entity>)()\n : ctx\n ) as Entity;\n\n const decisionResult = await flag.execute(context);\n\n return decisionResult;\n };\n\n return runner;\n}\n"],"mappings":";;;;;AAqBA,IAAI,eAAoC;;;;AAKxC,SAAgB,gBAAgB,UAA8B;AAC5D,gBAAe;;;;;AA2NjB,IAAa,cAAb,MAA+B;CAC7B,AAAQ;;;;;CAMR,AAAO,YAAY,AAAgB,SAAsC;EAAtC;AACjC,OAAK,aAAa,iCAAc,KAAK;EACrC,MAAM,YAAY,KAAK,WAAW;AAElC,MAAI,UAAU,IAAI,QAAQ,IAAI,CAC5B,OAAM,IAAI,MAAM,0BAA0B,QAAQ,IAAI,mBAAmB;AAG3E,YAAU,IAAI,QAAQ,KAAK,KAAK;;CAGlC,AAAQ,aAAgC;EACtC,MAAM,MAAM,+BAAY;AAExB,gDAAI,IAAK,SAAS;GAChB,MAAM,EACJ,QACA,YACA,aACA,SACA,OACA,SACA,YACE,IAAI;AAER,UAAO;IACG;IACR;IACA,SAAS;KACP;KACA;KACA;KACA;KACA;KACD;IACD,OAAO;IACR;;EAGH,MAAM,WAAW,8CAAmB,UAAU;AAE9C,MAAI,UAAU;GACZ,MAAM,EAAE,YAAY,MAAM,OAAO,cAAc;AAE/C,UAAO;IACL,QAAQ,WAAW;IACnB;IACA,OAAO;KACL;KACA;KACA;KACA,WAAW,SAAS;KACpB,cAAc,cAAc;AAE1B,aADa,SAAS;;KAGzB;IACD,SAAS;IACV;;AAGH,QAAM,IAAI,MACR,uGACD;;;;;;;CAQH,MAAa,QAAQ,KAAqB;EACxC,MAAM,EAAE,QAAQ,UAAU,qBAAqB,KAAK;EAEpD,MAAM,sBAAsB,YAAY,KAAK;EAC7C,MAAM,WACN,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U;AAKjD,QAAO,MAAM,eAAgB,KAAK;AAChC,MAAI,4CAAC,IAAK,UACR,OAAM,IAAI,MACR,sEACD;EAGH,MAAM,UACN,OAAO,QAAQ,aACf,MAAO,KAA0C,GACjD;AAKA,SAFuB,MAAM,OAAK,QAAQ,QAAQ;;AAKpD,QAAO"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-DL3ucTiT.js');
|
|
2
2
|
require('../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../error-codes-Ds0bnPvT.js');
|
|
4
|
-
require('../commandkit-
|
|
4
|
+
require('../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-C6GtfAPW.js');
|
|
@@ -22,19 +22,19 @@ require('../types-q0Nm882H.js');
|
|
|
22
22
|
require('../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../utils-KsNof0Xz.js');
|
|
25
|
-
require('../types-package-
|
|
25
|
+
require('../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../constants-BOOGN85p.js');
|
|
27
27
|
require('../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../signals-ChFMD7mB.js');
|
|
29
29
|
require('../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../MessageCommandParser-
|
|
30
|
+
require('../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../router-Dn35v30f.js');
|
|
34
|
-
require('../common-
|
|
34
|
+
require('../common-BkRtx9ij.js');
|
|
35
35
|
require('../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../store-CM6pWVZh.js');
|
|
37
|
-
const require_feature_flags = require('../feature-flags-
|
|
37
|
+
const require_feature_flags = require('../feature-flags-B3KR7vGo.js');
|
|
38
38
|
|
|
39
39
|
exports.FeatureFlag = require_feature_flags.FeatureFlag;
|
|
40
40
|
exports.flag = require_feature_flags.flag;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
|
3
3
|
require('./colors-DL3ucTiT.js');
|
|
4
4
|
const require_ActionRow = require('./ActionRow-CbdGFWMT.js');
|
|
5
5
|
const require_error_codes = require('./error-codes-Ds0bnPvT.js');
|
|
6
|
-
const require_commandkit = require('./commandkit-
|
|
6
|
+
const require_commandkit = require('./commandkit-D_X1yJyt.js');
|
|
7
7
|
require('./common-CcfjYnPG.js');
|
|
8
8
|
require('./common-vnMIelAE.js');
|
|
9
9
|
const require_container = require('./container-C6GtfAPW.js');
|
|
@@ -24,23 +24,23 @@ require('./types-q0Nm882H.js');
|
|
|
24
24
|
const require_resolve_file_url = require('./resolve-file-url-ChIyw-Vf.js');
|
|
25
25
|
require('./runtime-DB9CiPfe.js');
|
|
26
26
|
require('./utils-KsNof0Xz.js');
|
|
27
|
-
require('./types-package-
|
|
27
|
+
require('./types-package-D2_jGQvq.js');
|
|
28
28
|
require('./constants-BOOGN85p.js');
|
|
29
29
|
const require_EventWorkerContext = require('./EventWorkerContext-Dq29tieI.js');
|
|
30
30
|
const require_signals = require('./signals-ChFMD7mB.js');
|
|
31
31
|
const require_helpers = require('./helpers-Dl8wW6aO.js');
|
|
32
|
-
const require_MessageCommandParser = require('./MessageCommandParser-
|
|
32
|
+
const require_MessageCommandParser = require('./MessageCommandParser-D4NQu2od.js');
|
|
33
33
|
const require_CommandsRouter = require('./CommandsRouter-Dmzw-ikm.js');
|
|
34
34
|
const require_EventsRouter = require('./EventsRouter-3Gygh-km.js');
|
|
35
35
|
require('./router-Dn35v30f.js');
|
|
36
|
-
require('./common-
|
|
36
|
+
require('./common-BkRtx9ij.js');
|
|
37
37
|
require('./CommandKitEventsChannel-BtRzr3Tz.js');
|
|
38
38
|
require('./store-CM6pWVZh.js');
|
|
39
39
|
require('./app-HN1cVg8J.js');
|
|
40
40
|
require('./ILogger-dQ7Y9X1f.js');
|
|
41
|
-
const require_version = require('./version-
|
|
42
|
-
const require_feature_flags = require('./feature-flags-
|
|
43
|
-
const require_init = require('./init-
|
|
41
|
+
const require_version = require('./version-CK3uSO6m.js');
|
|
42
|
+
const require_feature_flags = require('./feature-flags-B3KR7vGo.js');
|
|
43
|
+
const require_init = require('./init-PfRfhy7q.js');
|
|
44
44
|
let discord_js = require("discord.js");
|
|
45
45
|
discord_js = require_chunk.__toESM(discord_js);
|
|
46
46
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
|
-
const require_commandkit = require('./commandkit-
|
|
2
|
+
const require_commandkit = require('./commandkit-D_X1yJyt.js');
|
|
3
3
|
const require_constants = require('./constants-B5_Ta7PR.js');
|
|
4
4
|
const require_CompilerPlugin = require('./CompilerPlugin-M8r3yNAl.js');
|
|
5
|
-
const require_types_package = require('./types-package-
|
|
6
|
-
const require_common = require('./common-
|
|
5
|
+
const require_types_package = require('./types-package-D2_jGQvq.js');
|
|
6
|
+
const require_common = require('./common-BkRtx9ij.js');
|
|
7
7
|
let node_fs = require("node:fs");
|
|
8
8
|
node_fs = require_chunk.__toESM(node_fs);
|
|
9
9
|
let node_path = require("node:path");
|
|
@@ -28,20 +28,17 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
28
28
|
const { setCLIEnv } = await Promise.resolve().then(() => require("./cli/env.js"));
|
|
29
29
|
const program = new Command("commandkit");
|
|
30
30
|
program.command("dev").version(version).description("Start your bot in development mode.").option("-c, --config [path]", "Path to your commandkit config file.", "./commandkit.js").action(() => {
|
|
31
|
-
|
|
32
|
-
bootstrapDevelopmentServer(options$1.config);
|
|
31
|
+
bootstrapDevelopmentServer(program.opts().config);
|
|
33
32
|
});
|
|
34
33
|
program.command("info").description("Show information about the system which can be used to report bugs.").action(async () => {
|
|
35
34
|
await showInformation();
|
|
36
35
|
});
|
|
37
36
|
program.command("start").description("Start your bot in production mode after running the build command.").option("-c, --config [path]", "Path to your commandkit config file.").action(() => {
|
|
38
|
-
|
|
39
|
-
bootstrapProductionServer(options$1.config);
|
|
37
|
+
bootstrapProductionServer(program.opts().config);
|
|
40
38
|
});
|
|
41
39
|
program.command("build").description("Build your project for production usage.").option("-c, --config [path]", "Path to your commandkit config file.").action(() => {
|
|
42
40
|
setCLIEnv();
|
|
43
|
-
|
|
44
|
-
return createProductionBuild(options$1.config);
|
|
41
|
+
return createProductionBuild(program.opts().config);
|
|
45
42
|
});
|
|
46
43
|
program.command("create").description("Create new files using built-in templates or custom plugin templates").argument("<template>", "The template to use (e.g. command, event, or custom plugin template)").argument("[args...]", "Additional arguments for the template").action(async (template, args) => {
|
|
47
44
|
setCLIEnv();
|
|
@@ -63,12 +60,11 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
63
60
|
await generateEvent(name);
|
|
64
61
|
return;
|
|
65
62
|
}
|
|
66
|
-
|
|
63
|
+
require_common.panic(`Template "${template}" not found. Available templates: ${Array.from(new Set([
|
|
67
64
|
"command",
|
|
68
65
|
"event",
|
|
69
66
|
...Array.from(runtime.getTemplates().keys())
|
|
70
|
-
])).map((t) => `"${t}"`);
|
|
71
|
-
require_common.panic(`Template "${template}" not found. Available templates: ${valid.join(", ")}`);
|
|
67
|
+
])).map((t) => `"${t}"`).join(", ")}`);
|
|
72
68
|
}
|
|
73
69
|
await templateHandler(args);
|
|
74
70
|
} catch (e) {
|
|
@@ -92,4 +88,4 @@ Object.defineProperty(exports, 'bootstrapCommandkitCLI', {
|
|
|
92
88
|
return bootstrapCommandkitCLI;
|
|
93
89
|
}
|
|
94
90
|
});
|
|
95
|
-
//# sourceMappingURL=init-
|
|
91
|
+
//# sourceMappingURL=init-PfRfhy7q.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-
|
|
1
|
+
{"version":3,"file":"init-PfRfhy7q.js","names":[],"sources":["../src/cli/init.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { generateTypesPackage } from '../utils/types-package';\nimport { loadConfigFile } from '../config/loader';\nimport {\n CompilerPlugin,\n CompilerPluginRuntime,\n isCompilerPlugin,\n} from '../plugins';\nimport { panic } from './common';\nimport { COMMANDKIT_CWD } from '../utils/constants';\n\n/**\n * Creates a command line interface for CommandKit.\n * @param argv The arguments passed to the CLI.\n * @param options The options passed to the CLI.\n */\nexport async function bootstrapCommandkitCLI(\n argv: string[],\n options?: import('commander').ParseOptions | undefined,\n) {\n process.title = 'CommandKit CLI';\n\n // imports are lazily loaded when the cli is used, instead of loading it with the lib itself\n const { Command } = await import('commander');\n const { bootstrapDevelopmentServer } = await import('./development');\n const { bootstrapProductionServer, createProductionBuild } = await import(\n './production'\n );\n const { generateCommand, generateEvent } = await import('./generators');\n const { version } = await import('../version');\n const { showInformation } = await import('./information');\n const { setCLIEnv } = await import('./env');\n\n const program = new Command('commandkit');\n\n program\n .command('dev')\n .version(version)\n .description('Start your bot in development mode.')\n .option(\n '-c, --config [path]',\n 'Path to your commandkit config file.',\n './commandkit.js',\n )\n .action(() => {\n const options = program.opts();\n bootstrapDevelopmentServer(options.config);\n });\n\n program\n .command('info')\n .description(\n 'Show information about the system which can be used to report bugs.',\n )\n .action(async () => {\n await showInformation();\n });\n\n program\n .command('start')\n .description(\n 'Start your bot in production mode after running the build command.',\n )\n .option('-c, --config [path]', 'Path to your commandkit config file.')\n .action(() => {\n const options = program.opts();\n bootstrapProductionServer(options.config);\n });\n\n program\n .command('build')\n .description('Build your project for production usage.')\n .option('-c, --config [path]', 'Path to your commandkit config file.')\n .action(() => {\n setCLIEnv();\n const options = program.opts();\n return createProductionBuild(options.config);\n });\n\n program\n .command('create')\n .description(\n 'Create new files using built-in templates or custom plugin templates',\n )\n .argument(\n '<template>',\n 'The template to use (e.g. command, event, or custom plugin template)',\n )\n .argument('[args...]', 'Additional arguments for the template')\n .action(async (template, args) => {\n setCLIEnv();\n\n // Handle custom plugin templates\n const { plugins } = await loadConfigFile();\n const runtime = new CompilerPluginRuntime(\n plugins.filter((p) => isCompilerPlugin(p)) as CompilerPlugin[],\n );\n\n try {\n await runtime.init();\n const templateHandler = runtime.getTemplate(template);\n\n if (!templateHandler) {\n // Handle built-in templates\n if (template === 'command') {\n const [name] = args;\n if (!name) {\n panic('Command name is required');\n }\n await generateCommand(name);\n return;\n }\n\n if (template === 'event') {\n const [name] = args;\n if (!name) {\n panic('Event name is required');\n }\n await generateEvent(name);\n return;\n }\n\n const valid = Array.from(\n new Set([\n 'command',\n 'event',\n ...Array.from(runtime.getTemplates().keys()),\n ]),\n ).map((t) => `\"${t}\"`);\n\n panic(\n `Template \"${template}\" not found. Available templates: ${valid.join(', ')}`,\n );\n }\n\n await templateHandler(args);\n } catch (e: any) {\n panic(`Failed to execute template \"${template}\": ${e?.message || e}`);\n } finally {\n await runtime.destroy();\n }\n });\n\n const types = join(COMMANDKIT_CWD, 'node_modules', 'commandkit-types');\n\n if (!existsSync(types)) {\n await mkdir(types, { recursive: true }).catch(() => {});\n await generateTypesPackage(true).catch(() => {});\n }\n\n await program.parseAsync(argv, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,eAAsB,uBACtB,MACA,SACA;AACE,SAAQ,QAAQ;CAGhB,MAAM,EAAE,YAAY,MAAM,OAAO;CACjC,MAAM,EAAE,+BAA+B,2CAAM;CAC7C,MAAM,EAAE,2BAA2B,0BAA0B,2CAAM;CAGnE,MAAM,EAAE,iBAAiB,kBAAkB,2CAAM;CACjD,MAAM,EAAE,YAAY,2CAAM;CAC1B,MAAM,EAAE,oBAAoB,2CAAM;CAClC,MAAM,EAAE,cAAc,2CAAM;CAE5B,MAAM,UAAU,IAAI,QAAQ,aAAa;AAEzC,SACA,QAAQ,MAAM,CACd,QAAQ,QAAQ,CAChB,YAAY,sCAAsC,CAClD,OACE,uBACA,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AAgB,KAAK;WACpB,GAAQ;AACf,wBAAM,+BAA+B,SAAS,4CAAK,EAAG,YAAW,IAAI;YAC7D;AACR,SAAM,QAAQ,SAAS;;GAEzB;CAEF,MAAM,4BAAa,kCAAgB,gBAAgB,mBAAmB;AAEtE,KAAI,yBAAY,MAAM,EAAE;AACtB,oCAAY,OAAO,EAAE,WAAW,MAAM,CAAC,CAAC,YAAY,GAAG;AACvD,QAAM,2CAAqB,KAAK,CAAC,YAAY,GAAG;;AAGlD,OAAM,QAAQ,WAAW,MAAM,QAAQ"}
|
package/dist/kv/kv.js
CHANGED
|
@@ -141,8 +141,7 @@ var KV = class KV {
|
|
|
141
141
|
this.delete(key);
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
|
-
const
|
|
145
|
-
const deserialized = require_serde.deserializer(serialized);
|
|
144
|
+
const deserialized = require_serde.deserializer(JSON.parse(result.value));
|
|
146
145
|
if (key.includes(".")) return require_dotprops.getNestedValue(deserialized, key.split(".").slice(1).join("."));
|
|
147
146
|
return deserialized;
|
|
148
147
|
}
|
|
@@ -403,8 +402,7 @@ var KV = class KV {
|
|
|
403
402
|
*/
|
|
404
403
|
values() {
|
|
405
404
|
return this.statements.values.all(this.getCurrentTime()).map((row) => {
|
|
406
|
-
|
|
407
|
-
return require_serde.deserializer(serialized);
|
|
405
|
+
return require_serde.deserializer(JSON.parse(row.value));
|
|
408
406
|
});
|
|
409
407
|
}
|
|
410
408
|
/**
|
package/dist/kv/kv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv.js","names":[],"sources":["../../src/kv/kv.ts"],"sourcesContent":["import { DatabaseSync, StatementSync } from 'node:sqlite';\nimport { deserializer, serializer } from './serde';\nimport { getNestedValue, setNestedValue } from './dotprops';\n\nexport type { SerializedValue } from './serde';\n\n/**\n * Mathematical operators supported by the KV math method\n */\nexport type KvMathOperator = '+' | '-' | '*' | '/' | '^' | '%';\n\n/**\n * Configuration options for the KV store\n */\nexport interface KvOptions {\n /** Enable Write-Ahead Logging for better performance and durability */\n enableWAL?: boolean;\n /** Namespace for the key-value store table */\n namespace?: string;\n}\n\n/**\n * A key-value store implementation using SQLite\n *\n * This class provides a simple, persistent key-value storage solution\n * with support for namespaces, automatic cleanup, iteration, expiration, and JSON serialization.\n *\n * @example\n * ```typescript\n * const kv = new KV('data.db');\n *\n * // Store any JSON-serializable data\n * kv.set('user:123', { name: 'John', age: 30 });\n * kv.set('counter', 42);\n * kv.set('active', true);\n * kv.set('dates', [new Date(), new Date()]);\n *\n * // Use dot notation for nested properties\n * kv.set('user:123.name', 'John');\n * kv.set('user:123.settings.theme', 'dark');\n *\n * // Retrieve data\n * const user = kv.get('user:123'); // { name: 'John', age: 30, settings: { theme: 'dark' } }\n * const name = kv.get('user:123.name'); // 'John'\n * ```\n */\nexport class KV implements Disposable, AsyncDisposable {\n private db: DatabaseSync;\n private statements: Record<string, StatementSync> = {};\n\n /**\n * Creates a new KV store instance\n *\n * @param path - Database file path, buffer, URL, or existing DatabaseSync instance\n * @param options - Configuration options for the KV store\n */\n public constructor(\n path: string | Buffer | URL | DatabaseSync,\n private options: KvOptions = {\n enableWAL: true,\n namespace: 'commandkit_kv',\n },\n ) {\n this.db =\n path instanceof DatabaseSync\n ? path\n : new DatabaseSync(path, { open: true });\n\n if (options.enableWAL) {\n this.db.exec(/* sql */ `PRAGMA journal_mode = WAL;`);\n }\n\n const namespace = this.options.namespace ?? 'commandkit_kv';\n\n this.db.exec(/* sql */ `\n CREATE TABLE IF NOT EXISTS ${namespace} (\n key TEXT PRIMARY KEY,\n value TEXT,\n expires_at INTEGER\n )\n `);\n\n this.statements = {\n get: this.db.prepare(\n /* sql */ `SELECT value, expires_at FROM ${namespace} WHERE key = ?`,\n ),\n set: this.db.prepare(\n /* sql */ `INSERT OR REPLACE INTO ${namespace} (key, value, expires_at) VALUES (?, ?, ?)`,\n ),\n setex: this.db.prepare(\n /* sql */ `INSERT OR REPLACE INTO ${namespace} (key, value, expires_at) VALUES (?, ?, ?)`,\n ),\n delete: this.db.prepare(\n /* sql */ `DELETE FROM ${namespace} WHERE key = ?`,\n ),\n has: this.db.prepare(\n /* sql */ `SELECT COUNT(*) FROM ${namespace} WHERE key = ? AND (expires_at IS NULL OR expires_at > ?)`,\n ),\n keys: this.db.prepare(\n /* sql */ `SELECT key FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n values: this.db.prepare(\n /* sql */ `SELECT value FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n clear: this.db.prepare(/* sql */ `DELETE FROM ${namespace}`),\n count: this.db.prepare(\n /* sql */ `SELECT COUNT(*) FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n all: this.db.prepare(\n /* sql */ `SELECT key, value FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n expire: this.db.prepare(\n /* sql */ `UPDATE ${namespace} SET expires_at = ? WHERE key = ?`,\n ),\n ttl: this.db.prepare(\n /* sql */ `SELECT expires_at FROM ${namespace} WHERE key = ?`,\n ),\n namespaces: this.db.prepare(\n /* sql */ `SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'`,\n ),\n begin: this.db.prepare(/* sql */ `BEGIN TRANSACTION`),\n commit: this.db.prepare(/* sql */ `COMMIT`),\n rollback: this.db.prepare(/* sql */ `ROLLBACK`),\n };\n }\n\n /**\n * Gets the current timestamp in milliseconds\n */\n private getCurrentTime(): number {\n return Date.now();\n }\n\n /**\n * Checks if the database connection is open\n *\n * @returns `true` if the database is open, `false` otherwise\n */\n public isOpen(): boolean {\n return this.db.isOpen;\n }\n\n /**\n * Gets the underlying SQLite database instance\n *\n * @returns The DatabaseSync instance\n */\n public getDatabase(): DatabaseSync {\n return this.db;\n }\n\n /**\n * Closes the database connection\n */\n public close(): void {\n if (this.db.isOpen) this.db.close();\n }\n\n /**\n * Disposable implementation - closes the database when disposed\n */\n public [Symbol.dispose]() {\n this.close();\n }\n\n /**\n * AsyncDisposable implementation - closes the database when disposed\n */\n public async [Symbol.asyncDispose]() {\n this.close();\n }\n\n /**\n * Retrieves a value by key\n *\n * @param key - The key to retrieve (supports dot notation for nested properties)\n * @returns The value associated with the key, or `undefined` if not found or expired\n *\n * @example\n * ```typescript\n * // Store an object\n * kv.set('user:123', { name: 'John', age: 30, settings: { theme: 'dark' } });\n *\n * // Get the entire object\n * const user = kv.get('user:123');\n * // { name: 'John', age: 30, settings: { theme: 'dark' } }\n *\n * // Get nested properties using dot notation\n * const name = kv.get('user:123.name'); // 'John'\n * const theme = kv.get('user:123.settings.theme'); // 'dark'\n * ```\n */\n public get<T = any>(key: string): T | undefined {\n const result = this.statements.get.get(key);\n\n if (!result) return undefined;\n\n // Check if the key has expired\n if (\n result.expires_at &&\n Number(result.expires_at) <= this.getCurrentTime()\n ) {\n this.delete(key);\n return undefined;\n }\n\n const serialized = JSON.parse(result.value as string);\n const deserialized = deserializer(serialized);\n\n // Handle dot notation for nested properties\n if (key.includes('.')) {\n return getNestedValue(deserialized, key.split('.').slice(1).join('.'));\n }\n\n return deserialized;\n }\n\n /**\n * Sets a key-value pair\n *\n * @param key - The key to set (supports dot notation for nested properties)\n * @param value - The value to associate with the key (any JSON-serializable type)\n *\n * @example\n * ```typescript\n * // Store primitive values\n * kv.set('counter', 42);\n * kv.set('active', true);\n * kv.set('name', 'John');\n *\n * // Store objects\n * kv.set('user:123', { name: 'John', age: 30 });\n *\n * // Store arrays\n * kv.set('tags', ['javascript', 'typescript', 'sqlite']);\n *\n * // Store dates\n * kv.set('created', new Date());\n *\n * // Store maps and sets\n * kv.set('permissions', new Map([['admin', true], ['user', false]]));\n * kv.set('unique_ids', new Set([1, 2, 3, 4, 5]));\n *\n * // Use dot notation for nested properties\n * kv.set('user:123.settings.theme', 'dark');\n * kv.set('user:123.settings.notifications', true);\n * ```\n */\n public set(key: string, value: any): void {\n let serializedValue: string;\n\n if (key.includes('.')) {\n // Handle dot notation for nested properties\n const [baseKey, ...pathParts] = key.split('.');\n const path = pathParts.join('.');\n\n // Get existing value or create new object\n const existing = this.get(baseKey) || {};\n setNestedValue(existing, path, value);\n\n const serialized = serializer(existing);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.set.run(baseKey, serializedValue, null);\n } else {\n const serialized = serializer(value);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.set.run(key, serializedValue, null);\n }\n }\n\n /**\n * Sets a key-value pair with expiration\n *\n * @param key - The key to set (supports dot notation for nested properties)\n * @param value - The value to associate with the key (any JSON-serializable type)\n * @param ttl - Time to live in milliseconds\n *\n * @example\n * ```typescript\n * // Set with 1 hour expiration\n * kv.setex('session:123', { userId: 123, token: 'abc123' }, 60 * 60 * 1000);\n *\n * // Set with 5 minutes expiration\n * kv.setex('temp:data', { cached: true, timestamp: Date.now() }, 5 * 60 * 1000);\n *\n * // Use dot notation with expiration\n * kv.setex('user:123.temp_settings', { theme: 'light' }, 30 * 60 * 1000);\n * ```\n */\n public setex(key: string, value: any, ttl: number): void {\n const expiresAt = this.getCurrentTime() + ttl;\n let serializedValue: string;\n\n if (key.includes('.')) {\n // Handle dot notation for nested properties\n const [baseKey, ...pathParts] = key.split('.');\n const path = pathParts.join('.');\n\n // Get existing value or create new object\n const existing = this.get(baseKey) || {};\n setNestedValue(existing, path, value);\n\n const serialized = serializer(existing);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.setex.run(baseKey, serializedValue, expiresAt);\n } else {\n const serialized = serializer(value);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.setex.run(key, serializedValue, expiresAt);\n }\n }\n\n /**\n * Performs mathematical operations on numeric values in the KV store\n *\n * @param key - The key to perform math operation on (supports dot notation for nested properties)\n * @param operator - The mathematical operator to apply\n * @param value - The value to use in the operation\n * @returns The updated value after the mathematical operation\n * @throws Error if the existing value is not numeric or if the operation is invalid\n *\n * @example\n * ```typescript\n * // Initialize a counter\n * kv.set('counter', 10);\n *\n * // Increment by 5\n * const result1 = kv.math('counter', '+', 5); // 15\n *\n * // Multiply by 2\n * const result2 = kv.math('counter', '*', 2); // 30\n *\n * // Use with bigint\n * kv.set('big_counter', BigInt(1000));\n * const result3 = kv.math('big_counter', '+', BigInt(500)); // 1500n\n *\n * // Use with dot notation\n * kv.set('user:123', { score: 100, level: 5 });\n * const result4 = kv.math('user:123.score', '+', 50); // 150\n * ```\n */\n public math(\n key: string,\n operator: KvMathOperator,\n value: number | bigint,\n ): number | bigint {\n const existingValue = this.get(key);\n\n if (existingValue === undefined) {\n throw new Error(`Key '${key}' does not exist`);\n }\n\n if (\n typeof existingValue !== 'number' &&\n typeof existingValue !== 'bigint'\n ) {\n throw new Error(\n `Value at key '${key}' is not numeric. Expected number or bigint, got ${typeof existingValue}`,\n );\n }\n\n // Handle mixed number/bigint operations by converting to bigint\n const isBigIntOperation =\n typeof existingValue === 'bigint' || typeof value === 'bigint';\n\n const existing = isBigIntOperation\n ? typeof existingValue === 'bigint'\n ? existingValue\n : BigInt(existingValue)\n : (existingValue as number);\n const operand = isBigIntOperation\n ? typeof value === 'bigint'\n ? value\n : BigInt(value)\n : (value as number);\n\n let result: number | bigint;\n\n switch (operator) {\n case '+':\n result = (existing as any) + (operand as any);\n break;\n case '-':\n result = (existing as any) - (operand as any);\n break;\n case '*':\n result = (existing as any) * (operand as any);\n break;\n case '/':\n if (operand === 0 || operand === 0n) {\n throw new Error('Division by zero');\n }\n result = (existing as any) / (operand as any);\n break;\n case '^':\n if (isBigIntOperation && operand < 0n) {\n throw new Error(\n 'Exponentiation with negative exponent is not supported for bigint',\n );\n }\n result = (existing as any) ** (operand as any);\n break;\n case '%':\n if (operand === 0 || operand === 0n) {\n throw new Error('Modulo by zero');\n }\n result = (existing as any) % (operand as any);\n break;\n default:\n throw new Error(`Invalid operator: ${operator}`);\n }\n\n // Update the value in the store\n this.set(key, result);\n\n return result;\n }\n\n /**\n * Sets expiration for an existing key\n *\n * @param key - The key to set expiration for\n * @param ttl - Time to live in milliseconds\n * @returns `true` if the key exists and expiration was set, `false` otherwise\n *\n * @example\n * ```typescript\n * kv.set('user:123', { name: 'John', age: 30 });\n *\n * // Set 30 minute expiration\n * if (kv.expire('user:123', 30 * 60 * 1000)) {\n * console.log('Expiration set successfully');\n * }\n * ```\n */\n public expire(key: string, ttl: number): boolean {\n if (!this.has(key)) return false;\n\n const expiresAt = this.getCurrentTime() + ttl;\n this.statements.expire.run(expiresAt, key);\n return true;\n }\n\n /**\n * Gets the time to live for a key\n *\n * @param key - The key to check\n * @returns Time to live in milliseconds, or `-1` if the key doesn't exist, or `-2` if the key has no expiration\n *\n * @example\n * ```typescript\n * const ttl = kv.ttl('user:123');\n * if (ttl > 0) {\n * console.log(`Key expires in ${ttl}ms`);\n * } else if (ttl === -2) {\n * console.log('Key has no expiration');\n * } else {\n * console.log('Key does not exist');\n * }\n * ```\n */\n public ttl(key: string): number {\n const result = this.statements.ttl.get(key);\n\n if (!result) return -1; // Key doesn't exist\n\n if (!result.expires_at) return -2; // No expiration\n\n const remaining = Number(result.expires_at) - this.getCurrentTime();\n return remaining > 0 ? remaining : -1; // Expired or doesn't exist\n }\n\n /**\n * Deletes a key-value pair\n *\n * @param key - The key to delete\n *\n * @example\n * ```typescript\n * kv.delete('user:123');\n * kv.delete('user:123.settings.theme'); // Delete nested property\n * ```\n */\n public delete(key: string): void {\n this.statements.delete.run(key);\n }\n\n /**\n * Checks if a key exists and is not expired\n *\n * @param key - The key to check\n * @returns `true` if the key exists and is not expired, `false` otherwise\n *\n * @example\n * ```typescript\n * if (kv.has('user:123')) {\n * console.log('User exists and is not expired');\n * }\n *\n * if (kv.has('user:123.settings.theme')) {\n * console.log('Theme setting exists');\n * }\n * ```\n */\n public has(key: string): boolean {\n const result = this.statements.has.get(key, this.getCurrentTime());\n\n return (\n result?.count !== undefined &&\n result.count !== null &&\n Number(result.count) > 0\n );\n }\n\n /**\n * Gets all keys in the current namespace (excluding expired keys)\n *\n * @returns Array of all non-expired keys\n *\n * @example\n * ```typescript\n * const keys = kv.keys();\n * console.log('All keys:', keys);\n * ```\n */\n public keys(): string[] {\n const result = this.statements.keys.all(this.getCurrentTime());\n\n return result.map((row) => row.key as string);\n }\n\n /**\n * Gets all values in the current namespace (excluding expired keys)\n *\n * @returns Array of all non-expired values\n *\n * @example\n * ```typescript\n * const values = kv.values();\n * console.log('All values:', values);\n * ```\n */\n public values(): any[] {\n const result = this.statements.values.all(this.getCurrentTime());\n\n return result.map((row) => {\n const serialized = JSON.parse(row.value as string);\n return deserializer(serialized);\n });\n }\n\n /**\n * Gets the total number of key-value pairs in the current namespace (excluding expired keys)\n *\n * @returns The count of non-expired key-value pairs\n *\n * @example\n * ```typescript\n * const count = kv.count();\n * console.log(`Total entries: ${count}`);\n * ```\n */\n public count(): number {\n const result = this.statements.count.get(this.getCurrentTime());\n\n return Number(result?.count ?? 0);\n }\n\n /**\n * Removes all key-value pairs from the current namespace\n *\n * @example\n * ```typescript\n * kv.clear(); // Removes all entries in current namespace\n * ```\n */\n public clear(): void {\n this.statements.clear.run();\n }\n\n /**\n * Gets all key-value pairs as an object (excluding expired keys)\n *\n * @returns Object with all non-expired key-value pairs\n *\n * @example\n * ```typescript\n * const all = kv.all();\n * console.log('All entries:', all);\n * // Output: { 'key1': value1, 'key2': value2 }\n * ```\n */\n public all(): Record<string, any> {\n const result = this.statements.all.all(this.getCurrentTime());\n\n return Object.fromEntries(\n result.map((row) => {\n const serialized = JSON.parse(row.value as string);\n return [row.key as string, deserializer(serialized)];\n }),\n );\n }\n\n /**\n * Gets all available namespaces (tables) in the database\n *\n * @returns Array of namespace names\n *\n * @example\n * ```typescript\n * const namespaces = kv.namespaces();\n * console.log('Available namespaces:', namespaces);\n * ```\n */\n public namespaces(): string[] {\n const result = this.statements.namespaces.all();\n\n return result.map((row) => row.name as string);\n }\n\n /**\n * Gets the current namespace name\n *\n * @returns The current namespace string\n */\n public getCurrentNamespace(): string {\n return this.options.namespace ?? 'commandkit_kv';\n }\n\n /**\n * Creates a new KV instance with a different namespace\n *\n * @param namespace - The namespace to use for the new instance\n * @returns A new KV instance with the specified namespace\n *\n * @example\n * ```typescript\n * const userKv = kv.namespace('users');\n * const configKv = kv.namespace('config');\n *\n * userKv.set('123', { name: 'John', age: 30 });\n * configKv.set('theme', 'dark');\n * ```\n */\n public namespace(namespace: string): KV {\n return new KV(this.db, {\n enableWAL: this.options.enableWAL,\n namespace,\n });\n }\n\n /**\n * Iterator implementation for iterating over all non-expired key-value pairs\n *\n * @returns Iterator yielding [key, value] tuples\n *\n * @example\n * ```typescript\n * for (const [key, value] of kv) {\n * console.log(`${key}:`, value);\n * }\n *\n * // Or using spread operator\n * const entries = [...kv];\n * ```\n */\n public *[Symbol.iterator](): Iterator<[string, any]> {\n const result = this.statements.all.iterate(this.getCurrentTime());\n\n for (const row of result) {\n const serialized = JSON.parse(row.value as string);\n yield [row.key as string, deserializer(serialized)];\n }\n }\n\n /**\n * Executes a function within a transaction\n *\n * @param fn - Function to execute within the transaction (can be async)\n * @returns The result of the function\n *\n * @example\n * ```typescript\n * // Synchronous transaction\n * kv.transaction(() => {\n * kv.set('user:123', { name: 'John', age: 30 });\n * kv.set('user:456', { name: 'Jane', age: 25 });\n * // If any operation fails, all changes are rolled back\n * });\n *\n * // Async transaction\n * await kv.transaction(async () => {\n * kv.set('user:123', { name: 'John', age: 30 });\n * await someAsyncOperation();\n * kv.set('user:456', { name: 'Jane', age: 25 });\n * // If any operation fails, all changes are rolled back\n * });\n * ```\n */\n public async transaction<T>(fn: () => T | Promise<T>): Promise<T> {\n try {\n // Begin transaction\n this.statements.begin.run();\n\n // Execute the function\n const result = await fn();\n\n // Commit transaction\n this.statements.commit.run();\n\n return result;\n } catch (error) {\n // Rollback transaction on error\n this.statements.rollback.run();\n throw error;\n }\n }\n}\n\n/**\n * Opens a new KV instance\n *\n * @param path - Database file path, buffer, URL, or existing DatabaseSync instance\n * @param options - Configuration options for the KV store\n * @returns A new KV instance\n */\nexport function openKV(\n path: string | Buffer | URL | DatabaseSync = 'commandkit_kv.db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AAe,IAAsC;AAChE,MAAI;AAEF,QAAK,WAAW,MAAM,KAAK;GAG3B,MAAM,SAAS,MAAM,IAAI;AAGzB,QAAK,WAAW,OAAO,KAAK;AAE5B,UAAO;WACA,OAAO;AAEd,QAAK,WAAW,SAAS,KAAK;AAC9B,SAAM;;;;;;;;;;;AAYZ,SAAgB,OAChB,OAA6C,oBAC7C,UAAqB;CAAE,WAAW;CAAM,WAAW;CAAiB,EAC/D;AACH,QAAO,IAAI,GAAG,MAAM,QAAQ"}
|
|
1
|
+
{"version":3,"file":"kv.js","names":[],"sources":["../../src/kv/kv.ts"],"sourcesContent":["import { DatabaseSync, StatementSync } from 'node:sqlite';\nimport { deserializer, serializer } from './serde';\nimport { getNestedValue, setNestedValue } from './dotprops';\n\nexport type { SerializedValue } from './serde';\n\n/**\n * Mathematical operators supported by the KV math method\n */\nexport type KvMathOperator = '+' | '-' | '*' | '/' | '^' | '%';\n\n/**\n * Configuration options for the KV store\n */\nexport interface KvOptions {\n /** Enable Write-Ahead Logging for better performance and durability */\n enableWAL?: boolean;\n /** Namespace for the key-value store table */\n namespace?: string;\n}\n\n/**\n * A key-value store implementation using SQLite\n *\n * This class provides a simple, persistent key-value storage solution\n * with support for namespaces, automatic cleanup, iteration, expiration, and JSON serialization.\n *\n * @example\n * ```typescript\n * const kv = new KV('data.db');\n *\n * // Store any JSON-serializable data\n * kv.set('user:123', { name: 'John', age: 30 });\n * kv.set('counter', 42);\n * kv.set('active', true);\n * kv.set('dates', [new Date(), new Date()]);\n *\n * // Use dot notation for nested properties\n * kv.set('user:123.name', 'John');\n * kv.set('user:123.settings.theme', 'dark');\n *\n * // Retrieve data\n * const user = kv.get('user:123'); // { name: 'John', age: 30, settings: { theme: 'dark' } }\n * const name = kv.get('user:123.name'); // 'John'\n * ```\n */\nexport class KV implements Disposable, AsyncDisposable {\n private db: DatabaseSync;\n private statements: Record<string, StatementSync> = {};\n\n /**\n * Creates a new KV store instance\n *\n * @param path - Database file path, buffer, URL, or existing DatabaseSync instance\n * @param options - Configuration options for the KV store\n */\n public constructor(\n path: string | Buffer | URL | DatabaseSync,\n private options: KvOptions = {\n enableWAL: true,\n namespace: 'commandkit_kv',\n },\n ) {\n this.db =\n path instanceof DatabaseSync\n ? path\n : new DatabaseSync(path, { open: true });\n\n if (options.enableWAL) {\n this.db.exec(/* sql */ `PRAGMA journal_mode = WAL;`);\n }\n\n const namespace = this.options.namespace ?? 'commandkit_kv';\n\n this.db.exec(/* sql */ `\n CREATE TABLE IF NOT EXISTS ${namespace} (\n key TEXT PRIMARY KEY,\n value TEXT,\n expires_at INTEGER\n )\n `);\n\n this.statements = {\n get: this.db.prepare(\n /* sql */ `SELECT value, expires_at FROM ${namespace} WHERE key = ?`,\n ),\n set: this.db.prepare(\n /* sql */ `INSERT OR REPLACE INTO ${namespace} (key, value, expires_at) VALUES (?, ?, ?)`,\n ),\n setex: this.db.prepare(\n /* sql */ `INSERT OR REPLACE INTO ${namespace} (key, value, expires_at) VALUES (?, ?, ?)`,\n ),\n delete: this.db.prepare(\n /* sql */ `DELETE FROM ${namespace} WHERE key = ?`,\n ),\n has: this.db.prepare(\n /* sql */ `SELECT COUNT(*) FROM ${namespace} WHERE key = ? AND (expires_at IS NULL OR expires_at > ?)`,\n ),\n keys: this.db.prepare(\n /* sql */ `SELECT key FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n values: this.db.prepare(\n /* sql */ `SELECT value FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n clear: this.db.prepare(/* sql */ `DELETE FROM ${namespace}`),\n count: this.db.prepare(\n /* sql */ `SELECT COUNT(*) FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n all: this.db.prepare(\n /* sql */ `SELECT key, value FROM ${namespace} WHERE expires_at IS NULL OR expires_at > ?`,\n ),\n expire: this.db.prepare(\n /* sql */ `UPDATE ${namespace} SET expires_at = ? WHERE key = ?`,\n ),\n ttl: this.db.prepare(\n /* sql */ `SELECT expires_at FROM ${namespace} WHERE key = ?`,\n ),\n namespaces: this.db.prepare(\n /* sql */ `SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'`,\n ),\n begin: this.db.prepare(/* sql */ `BEGIN TRANSACTION`),\n commit: this.db.prepare(/* sql */ `COMMIT`),\n rollback: this.db.prepare(/* sql */ `ROLLBACK`),\n };\n }\n\n /**\n * Gets the current timestamp in milliseconds\n */\n private getCurrentTime(): number {\n return Date.now();\n }\n\n /**\n * Checks if the database connection is open\n *\n * @returns `true` if the database is open, `false` otherwise\n */\n public isOpen(): boolean {\n return this.db.isOpen;\n }\n\n /**\n * Gets the underlying SQLite database instance\n *\n * @returns The DatabaseSync instance\n */\n public getDatabase(): DatabaseSync {\n return this.db;\n }\n\n /**\n * Closes the database connection\n */\n public close(): void {\n if (this.db.isOpen) this.db.close();\n }\n\n /**\n * Disposable implementation - closes the database when disposed\n */\n public [Symbol.dispose]() {\n this.close();\n }\n\n /**\n * AsyncDisposable implementation - closes the database when disposed\n */\n public async [Symbol.asyncDispose]() {\n this.close();\n }\n\n /**\n * Retrieves a value by key\n *\n * @param key - The key to retrieve (supports dot notation for nested properties)\n * @returns The value associated with the key, or `undefined` if not found or expired\n *\n * @example\n * ```typescript\n * // Store an object\n * kv.set('user:123', { name: 'John', age: 30, settings: { theme: 'dark' } });\n *\n * // Get the entire object\n * const user = kv.get('user:123');\n * // { name: 'John', age: 30, settings: { theme: 'dark' } }\n *\n * // Get nested properties using dot notation\n * const name = kv.get('user:123.name'); // 'John'\n * const theme = kv.get('user:123.settings.theme'); // 'dark'\n * ```\n */\n public get<T = any>(key: string): T | undefined {\n const result = this.statements.get.get(key);\n\n if (!result) return undefined;\n\n // Check if the key has expired\n if (\n result.expires_at &&\n Number(result.expires_at) <= this.getCurrentTime()\n ) {\n this.delete(key);\n return undefined;\n }\n\n const serialized = JSON.parse(result.value as string);\n const deserialized = deserializer(serialized);\n\n // Handle dot notation for nested properties\n if (key.includes('.')) {\n return getNestedValue(deserialized, key.split('.').slice(1).join('.'));\n }\n\n return deserialized;\n }\n\n /**\n * Sets a key-value pair\n *\n * @param key - The key to set (supports dot notation for nested properties)\n * @param value - The value to associate with the key (any JSON-serializable type)\n *\n * @example\n * ```typescript\n * // Store primitive values\n * kv.set('counter', 42);\n * kv.set('active', true);\n * kv.set('name', 'John');\n *\n * // Store objects\n * kv.set('user:123', { name: 'John', age: 30 });\n *\n * // Store arrays\n * kv.set('tags', ['javascript', 'typescript', 'sqlite']);\n *\n * // Store dates\n * kv.set('created', new Date());\n *\n * // Store maps and sets\n * kv.set('permissions', new Map([['admin', true], ['user', false]]));\n * kv.set('unique_ids', new Set([1, 2, 3, 4, 5]));\n *\n * // Use dot notation for nested properties\n * kv.set('user:123.settings.theme', 'dark');\n * kv.set('user:123.settings.notifications', true);\n * ```\n */\n public set(key: string, value: any): void {\n let serializedValue: string;\n\n if (key.includes('.')) {\n // Handle dot notation for nested properties\n const [baseKey, ...pathParts] = key.split('.');\n const path = pathParts.join('.');\n\n // Get existing value or create new object\n const existing = this.get(baseKey) || {};\n setNestedValue(existing, path, value);\n\n const serialized = serializer(existing);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.set.run(baseKey, serializedValue, null);\n } else {\n const serialized = serializer(value);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.set.run(key, serializedValue, null);\n }\n }\n\n /**\n * Sets a key-value pair with expiration\n *\n * @param key - The key to set (supports dot notation for nested properties)\n * @param value - The value to associate with the key (any JSON-serializable type)\n * @param ttl - Time to live in milliseconds\n *\n * @example\n * ```typescript\n * // Set with 1 hour expiration\n * kv.setex('session:123', { userId: 123, token: 'abc123' }, 60 * 60 * 1000);\n *\n * // Set with 5 minutes expiration\n * kv.setex('temp:data', { cached: true, timestamp: Date.now() }, 5 * 60 * 1000);\n *\n * // Use dot notation with expiration\n * kv.setex('user:123.temp_settings', { theme: 'light' }, 30 * 60 * 1000);\n * ```\n */\n public setex(key: string, value: any, ttl: number): void {\n const expiresAt = this.getCurrentTime() + ttl;\n let serializedValue: string;\n\n if (key.includes('.')) {\n // Handle dot notation for nested properties\n const [baseKey, ...pathParts] = key.split('.');\n const path = pathParts.join('.');\n\n // Get existing value or create new object\n const existing = this.get(baseKey) || {};\n setNestedValue(existing, path, value);\n\n const serialized = serializer(existing);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.setex.run(baseKey, serializedValue, expiresAt);\n } else {\n const serialized = serializer(value);\n serializedValue = JSON.stringify(serialized);\n\n this.statements.setex.run(key, serializedValue, expiresAt);\n }\n }\n\n /**\n * Performs mathematical operations on numeric values in the KV store\n *\n * @param key - The key to perform math operation on (supports dot notation for nested properties)\n * @param operator - The mathematical operator to apply\n * @param value - The value to use in the operation\n * @returns The updated value after the mathematical operation\n * @throws Error if the existing value is not numeric or if the operation is invalid\n *\n * @example\n * ```typescript\n * // Initialize a counter\n * kv.set('counter', 10);\n *\n * // Increment by 5\n * const result1 = kv.math('counter', '+', 5); // 15\n *\n * // Multiply by 2\n * const result2 = kv.math('counter', '*', 2); // 30\n *\n * // Use with bigint\n * kv.set('big_counter', BigInt(1000));\n * const result3 = kv.math('big_counter', '+', BigInt(500)); // 1500n\n *\n * // Use with dot notation\n * kv.set('user:123', { score: 100, level: 5 });\n * const result4 = kv.math('user:123.score', '+', 50); // 150\n * ```\n */\n public math(\n key: string,\n operator: KvMathOperator,\n value: number | bigint,\n ): number | bigint {\n const existingValue = this.get(key);\n\n if (existingValue === undefined) {\n throw new Error(`Key '${key}' does not exist`);\n }\n\n if (\n typeof existingValue !== 'number' &&\n typeof existingValue !== 'bigint'\n ) {\n throw new Error(\n `Value at key '${key}' is not numeric. Expected number or bigint, got ${typeof existingValue}`,\n );\n }\n\n // Handle mixed number/bigint operations by converting to bigint\n const isBigIntOperation =\n typeof existingValue === 'bigint' || typeof value === 'bigint';\n\n const existing = isBigIntOperation\n ? typeof existingValue === 'bigint'\n ? existingValue\n : BigInt(existingValue)\n : (existingValue as number);\n const operand = isBigIntOperation\n ? typeof value === 'bigint'\n ? value\n : BigInt(value)\n : (value as number);\n\n let result: number | bigint;\n\n switch (operator) {\n case '+':\n result = (existing as any) + (operand as any);\n break;\n case '-':\n result = (existing as any) - (operand as any);\n break;\n case '*':\n result = (existing as any) * (operand as any);\n break;\n case '/':\n if (operand === 0 || operand === 0n) {\n throw new Error('Division by zero');\n }\n result = (existing as any) / (operand as any);\n break;\n case '^':\n if (isBigIntOperation && operand < 0n) {\n throw new Error(\n 'Exponentiation with negative exponent is not supported for bigint',\n );\n }\n result = (existing as any) ** (operand as any);\n break;\n case '%':\n if (operand === 0 || operand === 0n) {\n throw new Error('Modulo by zero');\n }\n result = (existing as any) % (operand as any);\n break;\n default:\n throw new Error(`Invalid operator: ${operator}`);\n }\n\n // Update the value in the store\n this.set(key, result);\n\n return result;\n }\n\n /**\n * Sets expiration for an existing key\n *\n * @param key - The key to set expiration for\n * @param ttl - Time to live in milliseconds\n * @returns `true` if the key exists and expiration was set, `false` otherwise\n *\n * @example\n * ```typescript\n * kv.set('user:123', { name: 'John', age: 30 });\n *\n * // Set 30 minute expiration\n * if (kv.expire('user:123', 30 * 60 * 1000)) {\n * console.log('Expiration set successfully');\n * }\n * ```\n */\n public expire(key: string, ttl: number): boolean {\n if (!this.has(key)) return false;\n\n const expiresAt = this.getCurrentTime() + ttl;\n this.statements.expire.run(expiresAt, key);\n return true;\n }\n\n /**\n * Gets the time to live for a key\n *\n * @param key - The key to check\n * @returns Time to live in milliseconds, or `-1` if the key doesn't exist, or `-2` if the key has no expiration\n *\n * @example\n * ```typescript\n * const ttl = kv.ttl('user:123');\n * if (ttl > 0) {\n * console.log(`Key expires in ${ttl}ms`);\n * } else if (ttl === -2) {\n * console.log('Key has no expiration');\n * } else {\n * console.log('Key does not exist');\n * }\n * ```\n */\n public ttl(key: string): number {\n const result = this.statements.ttl.get(key);\n\n if (!result) return -1; // Key doesn't exist\n\n if (!result.expires_at) return -2; // No expiration\n\n const remaining = Number(result.expires_at) - this.getCurrentTime();\n return remaining > 0 ? remaining : -1; // Expired or doesn't exist\n }\n\n /**\n * Deletes a key-value pair\n *\n * @param key - The key to delete\n *\n * @example\n * ```typescript\n * kv.delete('user:123');\n * kv.delete('user:123.settings.theme'); // Delete nested property\n * ```\n */\n public delete(key: string): void {\n this.statements.delete.run(key);\n }\n\n /**\n * Checks if a key exists and is not expired\n *\n * @param key - The key to check\n * @returns `true` if the key exists and is not expired, `false` otherwise\n *\n * @example\n * ```typescript\n * if (kv.has('user:123')) {\n * console.log('User exists and is not expired');\n * }\n *\n * if (kv.has('user:123.settings.theme')) {\n * console.log('Theme setting exists');\n * }\n * ```\n */\n public has(key: string): boolean {\n const result = this.statements.has.get(key, this.getCurrentTime());\n\n return (\n result?.count !== undefined &&\n result.count !== null &&\n Number(result.count) > 0\n );\n }\n\n /**\n * Gets all keys in the current namespace (excluding expired keys)\n *\n * @returns Array of all non-expired keys\n *\n * @example\n * ```typescript\n * const keys = kv.keys();\n * console.log('All keys:', keys);\n * ```\n */\n public keys(): string[] {\n const result = this.statements.keys.all(this.getCurrentTime());\n\n return result.map((row) => row.key as string);\n }\n\n /**\n * Gets all values in the current namespace (excluding expired keys)\n *\n * @returns Array of all non-expired values\n *\n * @example\n * ```typescript\n * const values = kv.values();\n * console.log('All values:', values);\n * ```\n */\n public values(): any[] {\n const result = this.statements.values.all(this.getCurrentTime());\n\n return result.map((row) => {\n const serialized = JSON.parse(row.value as string);\n return deserializer(serialized);\n });\n }\n\n /**\n * Gets the total number of key-value pairs in the current namespace (excluding expired keys)\n *\n * @returns The count of non-expired key-value pairs\n *\n * @example\n * ```typescript\n * const count = kv.count();\n * console.log(`Total entries: ${count}`);\n * ```\n */\n public count(): number {\n const result = this.statements.count.get(this.getCurrentTime());\n\n return Number(result?.count ?? 0);\n }\n\n /**\n * Removes all key-value pairs from the current namespace\n *\n * @example\n * ```typescript\n * kv.clear(); // Removes all entries in current namespace\n * ```\n */\n public clear(): void {\n this.statements.clear.run();\n }\n\n /**\n * Gets all key-value pairs as an object (excluding expired keys)\n *\n * @returns Object with all non-expired key-value pairs\n *\n * @example\n * ```typescript\n * const all = kv.all();\n * console.log('All entries:', all);\n * // Output: { 'key1': value1, 'key2': value2 }\n * ```\n */\n public all(): Record<string, any> {\n const result = this.statements.all.all(this.getCurrentTime());\n\n return Object.fromEntries(\n result.map((row) => {\n const serialized = JSON.parse(row.value as string);\n return [row.key as string, deserializer(serialized)];\n }),\n );\n }\n\n /**\n * Gets all available namespaces (tables) in the database\n *\n * @returns Array of namespace names\n *\n * @example\n * ```typescript\n * const namespaces = kv.namespaces();\n * console.log('Available namespaces:', namespaces);\n * ```\n */\n public namespaces(): string[] {\n const result = this.statements.namespaces.all();\n\n return result.map((row) => row.name as string);\n }\n\n /**\n * Gets the current namespace name\n *\n * @returns The current namespace string\n */\n public getCurrentNamespace(): string {\n return this.options.namespace ?? 'commandkit_kv';\n }\n\n /**\n * Creates a new KV instance with a different namespace\n *\n * @param namespace - The namespace to use for the new instance\n * @returns A new KV instance with the specified namespace\n *\n * @example\n * ```typescript\n * const userKv = kv.namespace('users');\n * const configKv = kv.namespace('config');\n *\n * userKv.set('123', { name: 'John', age: 30 });\n * configKv.set('theme', 'dark');\n * ```\n */\n public namespace(namespace: string): KV {\n return new KV(this.db, {\n enableWAL: this.options.enableWAL,\n namespace,\n });\n }\n\n /**\n * Iterator implementation for iterating over all non-expired key-value pairs\n *\n * @returns Iterator yielding [key, value] tuples\n *\n * @example\n * ```typescript\n * for (const [key, value] of kv) {\n * console.log(`${key}:`, value);\n * }\n *\n * // Or using spread operator\n * const entries = [...kv];\n * ```\n */\n public *[Symbol.iterator](): Iterator<[string, any]> {\n const result = this.statements.all.iterate(this.getCurrentTime());\n\n for (const row of result) {\n const serialized = JSON.parse(row.value as string);\n yield [row.key as string, deserializer(serialized)];\n }\n }\n\n /**\n * Executes a function within a transaction\n *\n * @param fn - Function to execute within the transaction (can be async)\n * @returns The result of the function\n *\n * @example\n * ```typescript\n * // Synchronous transaction\n * kv.transaction(() => {\n * kv.set('user:123', { name: 'John', age: 30 });\n * kv.set('user:456', { name: 'Jane', age: 25 });\n * // If any operation fails, all changes are rolled back\n * });\n *\n * // Async transaction\n * await kv.transaction(async () => {\n * kv.set('user:123', { name: 'John', age: 30 });\n * await someAsyncOperation();\n * kv.set('user:456', { name: 'Jane', age: 25 });\n * // If any operation fails, all changes are rolled back\n * });\n * ```\n */\n public async transaction<T>(fn: () => T | Promise<T>): Promise<T> {\n try {\n // Begin transaction\n this.statements.begin.run();\n\n // Execute the function\n const result = await fn();\n\n // Commit transaction\n this.statements.commit.run();\n\n return result;\n } catch (error) {\n // Rollback transaction on error\n this.statements.rollback.run();\n throw error;\n }\n }\n}\n\n/**\n * Opens a new KV instance\n *\n * @param path - Database file path, buffer, URL, or existing DatabaseSync instance\n * @param options - Configuration options for the KV store\n * @returns A new KV instance\n */\nexport function openKV(\n path: string | Buffer | URL | DatabaseSync = 'commandkit_kv.db',\n options: KvOptions = { enableWAL: true, namespace: 'commandkit_kv' },\n): KV {\n return new KV(path, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,IAAa,KAAb,MAAa,GAA0C;CACrD,AAAQ;CACR,AAAQ,aAA4C,EAAE;;;;;;;CAQtD,AAAO,YACP,MACA,AAAQ,UAAqB;EAC3B,WAAW;EACX,WAAW;EACZ,EACD;EAJQ;AAKN,OAAK,KACL,gBAAgB,2BAChB,OACA,IAAI,yBAAa,MAAM,EAAE,MAAM,MAAM,CAAC;AAEtC,MAAI,QAAQ,UACV,MAAK,GAAG,KAAc,6BAA6B;EAGrD,MAAM,YAAY,KAAK,QAAQ,aAAa;AAE5C,OAAK,GAAG,KAAc;mCACS,UAAU;;;;;MAKvC;AAEF,OAAK,aAAa;GAChB,KAAK,KAAK,GAAG,QACF,iCAAiC,UAAU,gBACrD;GACD,KAAK,KAAK,GAAG,QACF,0BAA0B,UAAU,4CAC9C;GACD,OAAO,KAA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;;;;;;;CAcH,AAAO,aAAuB;AAG5B,SAFe,KAAK,WAAW,WAAW,KAAK,CAEjC,KAAK,QAAQ,IAAI,KAAe;;;;;;;CAQhD,AAAO,sBAA8B;AACnC,SAAO,KAAK,QAAQ,aAAa;;;;;;;;;;;;;;;;;CAkBnC,AAAO,UAAU,WAAuB;AACtC,SAAO,IAAI,GAAG,KAAK,IAAI;GACrB,WAAW,KAAK,QAAQ;GACxB;GACD,CAAC;;;;;;;;;;;;;;;;;CAkBJ,EAAS,OAAO,YAAqC;EACnD,MAAM,SAAS,KAAK,WAAW,IAAI,QAAQ,KAAK,gBAAgB,CAAC;AAEjE,OAAK,MAAM,OAAO,QAAQ;GACxB,MAAM,aAAa,KAAK,MAAM,IAAI,MAAgB;AAClD,SAAM,CAAC,IAAI,KAAe,2BAAa,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BvD,MAAa,YAAe,IAAsC;AAChE,MAAI;AAEF,QAAK,WAAW,MAAM,KAAK;GAG3B,MAAM,SAAS,MAAM,IAAI;AAGzB,QAAK,WAAW,OAAO,KAAK;AAE5B,UAAO;WACA,OAAO;AAEd,QAAK,WAAW,SAAS,KAAK;AAC9B,SAAM;;;;;;;;;;;AAYZ,SAAgB,OAChB,OAA6C,oBAC7C,UAAqB;CAAE,WAAW;CAAM,WAAW;CAAiB,EAC/D;AACH,QAAO,IAAI,GAAG,MAAM,QAAQ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-DL3ucTiT.js');
|
|
2
2
|
require('../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
4
|
+
const require_commandkit = require('../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-C6GtfAPW.js');
|
|
@@ -22,16 +22,16 @@ require('../types-q0Nm882H.js');
|
|
|
22
22
|
require('../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../utils-KsNof0Xz.js');
|
|
25
|
-
require('../types-package-
|
|
25
|
+
require('../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../constants-BOOGN85p.js');
|
|
27
27
|
require('../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../signals-ChFMD7mB.js');
|
|
29
29
|
require('../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../MessageCommandParser-
|
|
30
|
+
require('../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../router-Dn35v30f.js');
|
|
34
|
-
require('../common-
|
|
34
|
+
require('../common-BkRtx9ij.js');
|
|
35
35
|
require('../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../store-CM6pWVZh.js');
|
|
37
37
|
|
package/dist/logger/Logger.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-DL3ucTiT.js');
|
|
2
2
|
require('../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
4
|
+
const require_commandkit = require('../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-C6GtfAPW.js');
|
|
@@ -22,16 +22,16 @@ require('../types-q0Nm882H.js');
|
|
|
22
22
|
require('../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../utils-KsNof0Xz.js');
|
|
25
|
-
require('../types-package-
|
|
25
|
+
require('../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../constants-BOOGN85p.js');
|
|
27
27
|
require('../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../signals-ChFMD7mB.js');
|
|
29
29
|
require('../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../MessageCommandParser-
|
|
30
|
+
require('../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../router-Dn35v30f.js');
|
|
34
|
-
require('../common-
|
|
34
|
+
require('../common-BkRtx9ij.js');
|
|
35
35
|
require('../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../store-CM6pWVZh.js');
|
|
37
37
|
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../colors-DL3ucTiT.js');
|
|
2
2
|
require('../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../commandkit-
|
|
4
|
+
const require_commandkit = require('../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../common-CcfjYnPG.js');
|
|
6
6
|
require('../common-vnMIelAE.js');
|
|
7
7
|
require('../container-C6GtfAPW.js');
|
|
@@ -22,16 +22,16 @@ require('../types-q0Nm882H.js');
|
|
|
22
22
|
require('../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../utils-KsNof0Xz.js');
|
|
25
|
-
require('../types-package-
|
|
25
|
+
require('../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../constants-BOOGN85p.js');
|
|
27
27
|
require('../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../signals-ChFMD7mB.js');
|
|
29
29
|
require('../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../MessageCommandParser-
|
|
30
|
+
require('../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../router-Dn35v30f.js');
|
|
34
|
-
require('../common-
|
|
34
|
+
require('../common-BkRtx9ij.js');
|
|
35
35
|
require('../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../store-CM6pWVZh.js');
|
|
37
37
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-DL3ucTiT.js');
|
|
2
2
|
require('../../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-C6GtfAPW.js');
|
|
@@ -22,16 +22,16 @@ require('../../types-q0Nm882H.js');
|
|
|
22
22
|
require('../../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../../utils-KsNof0Xz.js');
|
|
25
|
-
require('../../types-package-
|
|
25
|
+
require('../../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../../constants-BOOGN85p.js');
|
|
27
27
|
require('../../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../../signals-ChFMD7mB.js');
|
|
29
29
|
require('../../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../../MessageCommandParser-
|
|
30
|
+
require('../../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../../router-Dn35v30f.js');
|
|
34
|
-
require('../../common-
|
|
34
|
+
require('../../common-BkRtx9ij.js');
|
|
35
35
|
require('../../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../../store-CM6pWVZh.js');
|
|
37
37
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../colors-DL3ucTiT.js');
|
|
2
2
|
require('../../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../common-vnMIelAE.js');
|
|
7
7
|
require('../../container-C6GtfAPW.js');
|
|
@@ -22,16 +22,16 @@ require('../../types-q0Nm882H.js');
|
|
|
22
22
|
require('../../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../../utils-KsNof0Xz.js');
|
|
25
|
-
require('../../types-package-
|
|
25
|
+
require('../../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../../constants-BOOGN85p.js');
|
|
27
27
|
require('../../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../../signals-ChFMD7mB.js');
|
|
29
29
|
require('../../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../../MessageCommandParser-
|
|
30
|
+
require('../../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../../router-Dn35v30f.js');
|
|
34
|
-
require('../../common-
|
|
34
|
+
require('../../common-BkRtx9ij.js');
|
|
35
35
|
require('../../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../../store-CM6pWVZh.js');
|
|
37
37
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require('../../../colors-DL3ucTiT.js');
|
|
2
2
|
require('../../../ActionRow-CbdGFWMT.js');
|
|
3
3
|
require('../../../error-codes-Ds0bnPvT.js');
|
|
4
|
-
const require_commandkit = require('../../../commandkit-
|
|
4
|
+
const require_commandkit = require('../../../commandkit-D_X1yJyt.js');
|
|
5
5
|
require('../../../common-CcfjYnPG.js');
|
|
6
6
|
require('../../../common-vnMIelAE.js');
|
|
7
7
|
require('../../../container-C6GtfAPW.js');
|
|
@@ -22,16 +22,16 @@ require('../../../types-q0Nm882H.js');
|
|
|
22
22
|
require('../../../resolve-file-url-ChIyw-Vf.js');
|
|
23
23
|
require('../../../runtime-DB9CiPfe.js');
|
|
24
24
|
require('../../../utils-KsNof0Xz.js');
|
|
25
|
-
require('../../../types-package-
|
|
25
|
+
require('../../../types-package-D2_jGQvq.js');
|
|
26
26
|
require('../../../constants-BOOGN85p.js');
|
|
27
27
|
require('../../../EventWorkerContext-Dq29tieI.js');
|
|
28
28
|
require('../../../signals-ChFMD7mB.js');
|
|
29
29
|
require('../../../helpers-Dl8wW6aO.js');
|
|
30
|
-
require('../../../MessageCommandParser-
|
|
30
|
+
require('../../../MessageCommandParser-D4NQu2od.js');
|
|
31
31
|
require('../../../CommandsRouter-Dmzw-ikm.js');
|
|
32
32
|
require('../../../EventsRouter-3Gygh-km.js');
|
|
33
33
|
require('../../../router-Dn35v30f.js');
|
|
34
|
-
require('../../../common-
|
|
34
|
+
require('../../../common-BkRtx9ij.js');
|
|
35
35
|
require('../../../CommandKitEventsChannel-BtRzr3Tz.js');
|
|
36
36
|
require('../../../store-CM6pWVZh.js');
|
|
37
37
|
|