commandkit 1.2.1-dev.20260920033200 → 1.2.1-dev.20261013130331

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.
Files changed (185) hide show
  1. package/dist/analytics/analytics-engine.d.ts +1 -1
  2. package/dist/analytics/analytics-engine.js +1 -1
  3. package/dist/analytics/analytics-provider.d.ts +1 -1
  4. package/dist/analytics/analytics-provider.js +1 -1
  5. package/dist/analytics/constants.js.map +1 -1
  6. package/dist/analytics/utils.js +1 -1
  7. package/dist/{analytics-engine-Bz1p7ud3.d.ts → analytics-engine-uY6FDAEv.d.ts} +8 -2
  8. package/dist/app/commands/AppCommandRunner.d.ts +1 -1
  9. package/dist/app/commands/AppCommandRunner.js +1 -1
  10. package/dist/app/commands/Context.d.ts +1 -1
  11. package/dist/app/commands/Context.js +1 -1
  12. package/dist/app/commands/MessageCommandParser.js +1 -1
  13. package/dist/app/commands/MessageCommandParser.js.map +1 -1
  14. package/dist/app/commands/helpers.js.map +1 -1
  15. package/dist/app/events/EventWorkerContext.d.ts +1 -1
  16. package/dist/app/events/EventWorkerContext.js.map +1 -1
  17. package/dist/app/handlers/AppCommandHandler.d.ts +1 -1
  18. package/dist/app/handlers/AppCommandHandler.js +1 -1
  19. package/dist/app/handlers/AppEventsHandler.d.ts +1 -1
  20. package/dist/app/handlers/AppEventsHandler.js +1 -1
  21. package/dist/app/index.d.ts +1 -1
  22. package/dist/app/index.js +4 -4
  23. package/dist/app/interrupt/signals.js +2 -2
  24. package/dist/app/interrupt/signals.js.map +1 -1
  25. package/dist/app/middlewares/permissions.d.ts +1 -1
  26. package/dist/app/middlewares/permissions.js +1 -1
  27. package/dist/app/register/CommandRegistrar.d.ts +1 -1
  28. package/dist/app/register/CommandRegistrar.js +1 -1
  29. package/dist/app/router/CommandTree.js +1 -1
  30. package/dist/app/router/CommandsRouter.js +3 -1
  31. package/dist/app/router/CommandsRouter.js.map +1 -1
  32. package/dist/app/router/EventsRouter.js +3 -1
  33. package/dist/app/router/EventsRouter.js.map +1 -1
  34. package/dist/app/router/TreeArtifact.js.map +1 -1
  35. package/dist/app/router/index.js +3 -3
  36. package/dist/cli/app-process.d.ts +1 -1
  37. package/dist/cli/app-process.js +2 -2
  38. package/dist/cli/app-process.js.map +1 -1
  39. package/dist/cli/build.d.ts +1 -1
  40. package/dist/cli/build.js +25 -22
  41. package/dist/cli/build.js.map +1 -1
  42. package/dist/cli/common.d.ts +1 -1
  43. package/dist/cli/common.js +4 -4
  44. package/dist/cli/common.js.map +1 -1
  45. package/dist/cli/development.js +7 -8
  46. package/dist/cli/development.js.map +1 -1
  47. package/dist/cli/env.js +0 -1
  48. package/dist/cli/env.js.map +1 -1
  49. package/dist/cli/generators.js +3 -3
  50. package/dist/cli/generators.js.map +1 -1
  51. package/dist/cli/information.js +3 -3
  52. package/dist/cli/information.js.map +1 -1
  53. package/dist/cli/init.js +12 -10
  54. package/dist/cli/init.js.map +1 -1
  55. package/dist/cli/production.js +7 -7
  56. package/dist/cli/production.js.map +1 -1
  57. package/dist/cli/type-checker.js +2 -2
  58. package/dist/cli/type-checker.js.map +1 -1
  59. package/dist/cli/utils.js +0 -1
  60. package/dist/cli/utils.js.map +1 -1
  61. package/dist/{commandkit-gJ4YjTy4.js → commandkit-CzNV2oE8.js} +244 -196
  62. package/dist/commandkit-CzNV2oE8.js.map +1 -0
  63. package/dist/commandkit.d.ts +1 -1
  64. package/dist/commandkit.js +1 -1
  65. package/dist/components/common/EventInterceptor.js +0 -1
  66. package/dist/components/common/EventInterceptor.js.map +1 -1
  67. package/dist/components/common/element.js +1 -1
  68. package/dist/components/common/types.js +1 -1
  69. package/dist/components/display/common.js +1 -1
  70. package/dist/components/display/container.js +1 -1
  71. package/dist/components/display/file.js.map +1 -1
  72. package/dist/components/display/index.js +5 -5
  73. package/dist/components/display/label.js +1 -1
  74. package/dist/components/display/media-gallery.js +1 -1
  75. package/dist/components/display/poll.js.map +1 -1
  76. package/dist/components/display/section.js +1 -1
  77. package/dist/components/display/separator.js.map +1 -1
  78. package/dist/components/display/text-display.js +4 -2
  79. package/dist/components/display/text-display.js.map +1 -1
  80. package/dist/components/index.js +6 -6
  81. package/dist/components/interactive/action-row/ActionRow.js.map +1 -1
  82. package/dist/components/interactive/button/Button.js +1 -1
  83. package/dist/components/interactive/button/ButtonKit.js +1 -1
  84. package/dist/components/interactive/checkbox/checkbox.js +1 -1
  85. package/dist/components/interactive/modal/Modal.js +1 -1
  86. package/dist/components/interactive/modal/ModalKit.js +1 -1
  87. package/dist/components/interactive/radio/radio.js +1 -1
  88. package/dist/components/interactive/select-menu/ChannelSelectMenuKit.js +1 -1
  89. package/dist/components/interactive/select-menu/MentionableSelectMenuKit.js +1 -1
  90. package/dist/components/interactive/select-menu/RoleSelectMenuKit.js +1 -1
  91. package/dist/components/interactive/select-menu/SelectMenu.js +1 -1
  92. package/dist/components/interactive/select-menu/StringSelectMenuKit.js +1 -1
  93. package/dist/components/interactive/select-menu/UserSelectMenuKit.js +1 -1
  94. package/dist/components/interactive/select-menu/common.js +1 -1
  95. package/dist/config/config.d.ts +1 -1
  96. package/dist/config/config.js +1 -1
  97. package/dist/config/default.d.ts +1 -1
  98. package/dist/config/default.js +1 -1
  99. package/dist/config/loader.d.ts +1 -1
  100. package/dist/config/loader.js +1 -1
  101. package/dist/config/types.d.ts +1 -1
  102. package/dist/config/types.js +1 -1
  103. package/dist/config/utils.d.ts +1 -1
  104. package/dist/config/utils.js +4 -4
  105. package/dist/config/utils.js.map +1 -1
  106. package/dist/context/async-context.d.ts +1 -1
  107. package/dist/context/async-context.js +1 -1
  108. package/dist/context/environment.d.ts +1 -1
  109. package/dist/context/environment.js +1 -1
  110. package/dist/events/CommandKitEventsChannel.d.ts +1 -1
  111. package/dist/events/CommandKitEventsChannel.js +1 -1
  112. package/dist/events/CommandKitEventsChannel.js.map +1 -1
  113. package/dist/flags/FlagProvider.d.ts +1 -1
  114. package/dist/flags/FlagProvider.js +0 -1
  115. package/dist/flags/FlagProvider.js.map +1 -1
  116. package/dist/flags/feature-flags.d.ts +1 -1
  117. package/dist/flags/feature-flags.js +1 -1
  118. package/dist/flags/store.d.ts +1 -1
  119. package/dist/flags/store.js.map +1 -1
  120. package/dist/index.d.ts +1 -1
  121. package/dist/index.js +22 -22
  122. package/dist/kv/constants.js +0 -1
  123. package/dist/kv/constants.js.map +1 -1
  124. package/dist/kv/dotprops.js +0 -1
  125. package/dist/kv/dotprops.js.map +1 -1
  126. package/dist/kv/kv.js +6 -4
  127. package/dist/kv/kv.js.map +1 -1
  128. package/dist/kv/serde.js +1 -1
  129. package/dist/kv/serde.js.map +1 -1
  130. package/dist/logger/DefaultLogger.js +1 -1
  131. package/dist/logger/ILogger.js +1 -1
  132. package/dist/logger/Logger.js +1 -1
  133. package/dist/logger/NoopLogger.js +0 -1
  134. package/dist/logger/NoopLogger.js.map +1 -1
  135. package/dist/plugins/CompilerPlugin.d.ts +1 -1
  136. package/dist/plugins/CompilerPlugin.js +1 -1
  137. package/dist/plugins/CompilerPlugin.js.map +1 -1
  138. package/dist/plugins/PluginCommon.d.ts +1 -1
  139. package/dist/plugins/PluginCommon.js.map +1 -1
  140. package/dist/plugins/RuntimePlugin.d.ts +1 -1
  141. package/dist/plugins/RuntimePlugin.js +1 -1
  142. package/dist/plugins/RuntimePlugin.js.map +1 -1
  143. package/dist/plugins/index.d.ts +1 -1
  144. package/dist/plugins/index.js +3 -3
  145. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +1 -1
  146. package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +1 -1
  147. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +1 -1
  148. package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +1 -1
  149. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +1 -1
  150. package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +1 -1
  151. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +1 -1
  152. package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +1 -1
  153. package/dist/plugins/plugin-runtime/runtime.d.ts +1 -1
  154. package/dist/plugins/plugin-runtime/runtime.js +1 -1
  155. package/dist/plugins/types.d.ts +1 -1
  156. package/dist/plugins/types.js +1 -1
  157. package/dist/{rolldown-runtime-C_NdSu1c.js → rolldown-runtime-AN5ru5iW.js} +2 -3
  158. package/dist/types.d.ts +1 -1
  159. package/dist/types.js +1 -1
  160. package/dist/utils/colors.js.map +1 -1
  161. package/dist/utils/constants.js +0 -1
  162. package/dist/utils/constants.js.map +1 -1
  163. package/dist/utils/dev-hooks.d.ts +1 -1
  164. package/dist/utils/dev-hooks.js +1 -1
  165. package/dist/utils/error-codes.js +0 -1
  166. package/dist/utils/error-codes.js.map +1 -1
  167. package/dist/utils/resolve-file-url.js +1 -1
  168. package/dist/utils/resolve-file-url.js.map +1 -1
  169. package/dist/utils/types-package.js +3 -2
  170. package/dist/utils/types-package.js.map +1 -1
  171. package/dist/utils/useful-stuff/async-queue.js +0 -1
  172. package/dist/utils/useful-stuff/async-queue.js.map +1 -1
  173. package/dist/utils/useful-stuff/mutex.js +0 -1
  174. package/dist/utils/useful-stuff/mutex.js.map +1 -1
  175. package/dist/utils/useful-stuff/ratelimiter.js +0 -1
  176. package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
  177. package/dist/utils/useful-stuff/semaphore.js +0 -1
  178. package/dist/utils/useful-stuff/semaphore.js.map +1 -1
  179. package/dist/utils/utilities.js +1 -1
  180. package/dist/utils/warning.js +0 -1
  181. package/dist/utils/warning.js.map +1 -1
  182. package/dist/version.js +1 -2
  183. package/dist/version.js.map +1 -1
  184. package/package.json +18 -16
  185. package/dist/commandkit-gJ4YjTy4.js.map +0 -1
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/kv/dotprops.ts
4
3
  function getNestedValue(obj, path) {
5
4
  const keys = path.split(".");
@@ -1 +1 @@
1
- {"version":3,"file":"dotprops.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"dotprops.js","names":[],"sources":["../../src/kv/dotprops.ts"],"sourcesContent":["export function getNestedValue(obj: any, path: string): any {\n const keys = path.split('.');\n let current = obj;\n\n for (const key of keys) {\n if (current === null || current === undefined) {\n return undefined;\n }\n current = current[key];\n }\n\n return current;\n}\n\nexport function setNestedValue(obj: any, path: string, value: any): void {\n const keys = path.split('.');\n const lastKey = keys.pop()!;\n let current = obj;\n\n for (const key of keys) {\n if (current[key] === null || current[key] === undefined) {\n current[key] = {};\n }\n current = current[key];\n }\n\n current[lastKey] = value;\n}\n"],"mappings":";;AAAA,SAAgB,eAAe,KAAU,MAAmB;CAC1D,MAAM,OAAO,KAAK,MAAM,GAAG;CAC3B,IAAI,UAAU;CAEd,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,YAAY,QAAQ,YAAY,QAClC;EAEF,UAAU,QAAQ;CACpB;CAEA,OAAO;AACT;AAEA,SAAgB,eAAe,KAAU,MAAc,OAAkB;CACvE,MAAM,OAAO,KAAK,MAAM,GAAG;CAC3B,MAAM,UAAU,KAAK,IAAI;CACzB,IAAI,UAAU;CAEd,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,QAAQ,SAAS,QAAQ,QAAQ,SAAS,QAC5C,QAAQ,OAAO,CAAC;EAElB,UAAU,QAAQ;CACpB;CAEA,QAAQ,WAAW;AACrB"}
package/dist/kv/kv.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_kv_dotprops = require('./dotprops.js');
3
- const require_kv_serde = require('./serde.js');
2
+ const require_kv_dotprops = require("./dotprops.js");
3
+ const require_kv_serde = require("./serde.js");
4
4
  let node_sqlite = require("node:sqlite");
5
5
 
6
6
  //#region src/kv/kv.ts
@@ -140,7 +140,8 @@ var KV = class KV {
140
140
  this.delete(key);
141
141
  return;
142
142
  }
143
- const deserialized = require_kv_serde.deserializer(JSON.parse(result.value));
143
+ const serialized = JSON.parse(result.value);
144
+ const deserialized = require_kv_serde.deserializer(serialized);
144
145
  if (key.includes(".")) return require_kv_dotprops.getNestedValue(deserialized, key.split(".").slice(1).join("."));
145
146
  return deserialized;
146
147
  }
@@ -401,7 +402,8 @@ var KV = class KV {
401
402
  */
402
403
  values() {
403
404
  return this.statements.values.all(this.getCurrentTime()).map((row) => {
404
- return require_kv_serde.deserializer(JSON.parse(row.value));
405
+ const serialized = JSON.parse(row.value);
406
+ return require_kv_serde.deserializer(serialized);
405
407
  });
406
408
  }
407
409
  /**
package/dist/kv/kv.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"kv.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"kv.js","names":["DatabaseSync","deserializer","getNestedValue","serializer"],"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;CAY3C;CAXV,AAAQ;CACR,AAAQ,aAA4C,CAAC;;;;;;;CAQrD,AAAO,YACL,MACA,AAAQ,UAAqB;EAC3B,WAAW;EACX,WAAW;CACb,GACA;EAJQ;EAKR,KAAK,KACH,gBAAgBA,2BACZ,OACA,IAAIA,yBAAa,MAAM,EAAE,MAAM,KAAK,CAAC;EAE3C,IAAI,QAAQ,WACV,KAAK,GAAG,KAAe,4BAA4B;EAGrD,MAAM,YAAY,KAAK,QAAQ,aAAa;EA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AG,MAAM,OAAO;AAC7B"}
package/dist/kv/serde.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_kv_constants = require('./constants.js');
2
+ const require_kv_constants = require("./constants.js");
3
3
 
4
4
  //#region src/kv/serde.ts
5
5
  function serializer(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"serde.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"serde.js","names":[],"sources":["../../src/kv/serde.ts"],"sourcesContent":["import { SerializerType } from './constants';\n\nexport interface SerializedValue {\n t: SerializerType;\n v: any;\n}\n\nexport function serializer(value: any): SerializedValue {\n if (value === null) {\n return { t: SerializerType.Null, v: null };\n }\n\n if (value === undefined) {\n return { t: SerializerType.Undefined, v: undefined };\n }\n\n if (typeof value === 'string') {\n return { t: SerializerType.String, v: value };\n }\n\n if (typeof value === 'number') {\n return { t: SerializerType.Number, v: value };\n }\n\n if (typeof value === 'boolean') {\n return { t: SerializerType.Boolean, v: value };\n }\n\n if (typeof value === 'bigint') {\n return { t: SerializerType.BigInt, v: value.toString() };\n }\n\n if (value instanceof Date) {\n return { t: SerializerType.Date, v: value.toISOString() };\n }\n\n if (Array.isArray(value)) {\n return { t: SerializerType.Array, v: value };\n }\n\n if (value instanceof Map) {\n return { t: SerializerType.Map, v: Array.from(value.entries()) };\n }\n\n if (value instanceof Set) {\n return { t: SerializerType.Set, v: Array.from(value) };\n }\n\n if (Buffer.isBuffer(value)) {\n return { t: SerializerType.Buffer, v: value.toString('base64') };\n }\n\n if (value instanceof RegExp) {\n return {\n t: SerializerType.RegExp,\n v: { source: value.source, flags: value.flags },\n };\n }\n\n if (typeof value === 'object') {\n return { t: SerializerType.Object, v: value };\n }\n\n // Fallback to string\n return { t: SerializerType.String, v: String(value) };\n}\n\nexport function deserializer(serialized: SerializedValue): any {\n switch (serialized.t) {\n case SerializerType.Null:\n return null;\n case SerializerType.Undefined:\n return undefined;\n case SerializerType.String:\n return serialized.v;\n case SerializerType.Number:\n return serialized.v;\n case SerializerType.Boolean:\n return serialized.v;\n case SerializerType.BigInt:\n return BigInt(serialized.v);\n case SerializerType.Date:\n return new Date(serialized.v);\n case SerializerType.Array:\n return serialized.v;\n case SerializerType.Map:\n return new Map(serialized.v);\n case SerializerType.Set:\n return new Set(serialized.v);\n case SerializerType.Buffer:\n return Buffer.from(serialized.v, 'base64');\n case SerializerType.RegExp:\n return new RegExp(serialized.v.source, serialized.v.flags);\n case SerializerType.Object:\n return serialized.v;\n default:\n return serialized.v;\n }\n}\n"],"mappings":";;;;AAOA,SAAgB,WAAW,OAA6B;CACtD,IAAI,UAAU,MACZ,OAAO;EAAE;EAAwB,GAAG;CAAK;CAG3C,IAAI,UAAU,QACZ,OAAO;EAAE;EAA6B,GAAG;CAAU;CAGrD,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE;EAA0B,GAAG;CAAM;CAG9C,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE;EAA0B,GAAG;CAAM;CAG9C,IAAI,OAAO,UAAU,WACnB,OAAO;EAAE;EAA2B,GAAG;CAAM;CAG/C,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE;EAA0B,GAAG,MAAM,SAAS;CAAE;CAGzD,IAAI,iBAAiB,MACnB,OAAO;EAAE;EAAwB,GAAG,MAAM,YAAY;CAAE;CAG1D,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO;EAAE;EAAyB,GAAG;CAAM;CAG7C,IAAI,iBAAiB,KACnB,OAAO;EAAE;EAAuB,GAAG,MAAM,KAAK,MAAM,QAAQ,CAAC;CAAE;CAGjE,IAAI,iBAAiB,KACnB,OAAO;EAAE;EAAuB,GAAG,MAAM,KAAK,KAAK;CAAE;CAGvD,IAAI,OAAO,SAAS,KAAK,GACvB,OAAO;EAAE;EAA0B,GAAG,MAAM,SAAS,QAAQ;CAAE;CAGjE,IAAI,iBAAiB,QACnB,OAAO;EACL;EACA,GAAG;GAAE,QAAQ,MAAM;GAAQ,OAAO,MAAM;EAAM;CAChD;CAGF,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE;EAA0B,GAAG;CAAM;CAI9C,OAAO;EAAE;EAA0B,GAAG,OAAO,KAAK;CAAE;AACtD;AAEA,SAAgB,aAAa,YAAkC;CAC7D,QAAQ,WAAW,GAAnB;EACE,QACE,OAAO;EACT,QACE;EACF,QACE,OAAO,WAAW;EACpB,QACE,OAAO,WAAW;EACpB,QACE,OAAO,WAAW;EACpB,QACE,OAAO,OAAO,WAAW,CAAC;EAC5B,QACE,OAAO,IAAI,KAAK,WAAW,CAAC;EAC9B,QACE,OAAO,WAAW;EACpB,QACE,OAAO,IAAI,IAAI,WAAW,CAAC;EAC7B,SACE,OAAO,IAAI,IAAI,WAAW,CAAC;EAC7B,SACE,OAAO,OAAO,KAAK,WAAW,GAAG,QAAQ;EAC3C,SACE,OAAO,IAAI,OAAO,WAAW,EAAE,QAAQ,WAAW,EAAE,KAAK;EAC3D,QACE,OAAO,WAAW;EACpB,SACE,OAAO,WAAW;CACtB;AACF"}
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.DefaultLogger = require_commandkit.DefaultLogger;
@@ -1 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.Logger = require_commandkit.Logger;
5
5
  exports.createLogger = require_commandkit.createLogger;
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/logger/NoopLogger.ts
4
3
  /**
5
4
  * Noop logger implementation that does nothing.
@@ -1 +1 @@
1
- {"version":3,"file":"NoopLogger.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"NoopLogger.js","names":[],"sources":["../../src/logger/NoopLogger.ts"],"sourcesContent":["import { ILogger } from './ILogger';\n\n/**\n * Noop logger implementation that does nothing.\n */\nexport class NoopLogger implements ILogger {\n /**\n * Logs a debug message.\n * @param message The message to log.\n */\n public debug(message: any): void;\n /**\n * Logs a debug message using template literals.\n * @param strings The template literal strings.\n * @param values The values to interpolate.\n */\n public debug(strings: TemplateStringsArray, ...values: any[]): void;\n public debug(\n messageOrStrings: any | TemplateStringsArray,\n ...values: any[]\n ): void {}\n\n /**\n * Logs an error message.\n * @param message The error message to log.\n */\n public error(message: any): void;\n /**\n * Logs an error message using template literals.\n * @param strings The template literal strings.\n * @param values The values to interpolate.\n */\n public error(strings: TemplateStringsArray, ...values: any[]): void;\n public error(\n messageOrStrings: any | TemplateStringsArray,\n ...values: any[]\n ): void {}\n\n /**\n * Logs a default message.\n * @param message The message to log.\n */\n public log(message: any): void;\n /**\n * Logs a default message using template literals.\n * @param strings The template literal strings.\n * @param values The values to interpolate.\n */\n public log(strings: TemplateStringsArray, ...values: any[]): void;\n public log(\n messageOrStrings: any | TemplateStringsArray,\n ...values: any[]\n ): void {}\n\n /**\n * Logs an info message.\n * @param message The informational message to log.\n */\n public info(message: any): void;\n /**\n * Logs an info message using template literals.\n * @param strings The template literal strings.\n * @param values The values to interpolate.\n */\n public info(strings: TemplateStringsArray, ...values: any[]): void;\n public info(\n messageOrStrings: any | TemplateStringsArray,\n ...values: any[]\n ): void {}\n\n /**\n * Logs a warning message.\n * @param message The warning message to log.\n */\n public warn(message: any): void;\n /**\n * Logs a warning message using template literals.\n * @param strings The template literal strings.\n * @param values The values to interpolate.\n */\n public warn(strings: TemplateStringsArray, ...values: any[]): void;\n public warn(\n messageOrStrings: any | TemplateStringsArray,\n ...values: any[]\n ): void {}\n}\n"],"mappings":";;;;;AAKA,IAAa,aAAb,MAA2C;CAYzC,AAAO,MACL,kBACA,GAAG,QACG,CAAC;CAaT,AAAO,MACL,kBACA,GAAG,QACG,CAAC;CAaT,AAAO,IACL,kBACA,GAAG,QACG,CAAC;CAaT,AAAO,KACL,kBACA,GAAG,QACG,CAAC;CAaT,AAAO,KACL,kBACA,GAAG,QACG,CAAC;AACX"}
@@ -1,2 +1,2 @@
1
- import { G as CompilerPlugin, J as isCompilerPlugin, K as PluginTransformParameters, q as TransformedResult } from "../analytics-engine-Bz1p7ud3.js";
1
+ import { G as CompilerPlugin, J as isCompilerPlugin, K as PluginTransformParameters, q as TransformedResult } from "../analytics-engine-uY6FDAEv.js";
2
2
  export { CompilerPlugin, PluginTransformParameters, TransformedResult, isCompilerPlugin };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_plugins_PluginCommon = require('./PluginCommon.js');
2
+ const require_plugins_PluginCommon = require("./PluginCommon.js");
3
3
 
4
4
  //#region src/plugins/CompilerPlugin.ts
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"CompilerPlugin.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"CompilerPlugin.js","names":["PluginCommon","isPlugin"],"sources":["../../src/plugins/CompilerPlugin.ts"],"sourcesContent":["import {\n isPlugin,\n PluginCommon,\n PluginOptions,\n PluginType,\n} from './PluginCommon';\nimport { MaybeFalsey } from './types';\nimport { CompilerPluginRuntime } from './plugin-runtime/CompilerPluginRuntime';\n\n/**\n * The parameters for the transformation function of a compiler plugin.\n */\nexport interface PluginTransformParameters {\n /**\n * The code to be transformed.\n */\n code: string;\n /**\n * The filename of the code being transformed.\n */\n id: string;\n}\n\nexport interface TransformedResult {\n /**\n * The transformed code.\n */\n code?: string;\n /**\n * The source map for the transformed code, if applicable.\n */\n map?: string | null;\n}\n\n/**\n * CommandKit plugin that runs at compile time.\n */\nexport abstract class CompilerPlugin<\n T extends PluginOptions = PluginOptions,\n> extends PluginCommon<T, CompilerPluginRuntime> {\n /**\n * The type of the plugin, which is Compiler.\n */\n public readonly type = PluginType.Compiler;\n\n /**\n * Called when transformation is requested to this plugin\n * @param params The parameters for the transformation\n * @returns The transformed result\n */\n public async transform(\n params: PluginTransformParameters,\n ): Promise<MaybeFalsey<TransformedResult>> {\n return null;\n }\n}\n\n/**\n * Type guard to check if the given object is a CompilerPlugin.\n * @param plugin The object to check.\n * @returns Boolean indicating whether the object is a CompilerPlugin.\n */\nexport function isCompilerPlugin(plugin: unknown): plugin is CompilerPlugin {\n return (\n plugin instanceof CompilerPlugin ||\n (isPlugin(plugin) && plugin.type === PluginType.Compiler)\n );\n}\n"],"mappings":";;;;;;;AAqCA,IAAsB,iBAAtB,cAEUA,0CAAuC;;;;CAI/C,AAAgB;;;;;;CAOhB,MAAa,UACX,QACyC;EACzC,OAAO;CACT;AACF;;;;;;AAOA,SAAgB,iBAAiB,QAA2C;CAC1E,OACE,kBAAkB,kBACjBC,sCAAS,MAAM,KAAK,OAAO;AAEhC"}
@@ -1,2 +1,2 @@
1
- import { B as isPlugin, L as PluginCommon, R as PluginOptions, z as PluginType } from "../analytics-engine-Bz1p7ud3.js";
1
+ import { B as isPlugin, L as PluginCommon, R as PluginOptions, z as PluginType } from "../analytics-engine-uY6FDAEv.js";
2
2
  export { PluginCommon, PluginOptions, PluginType, isPlugin };
@@ -1 +1 @@
1
- {"version":3,"file":"PluginCommon.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"PluginCommon.js","names":["randomUUID"],"sources":["../../src/plugins/PluginCommon.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { CommonPluginRuntime } from './plugin-runtime/runtime';\n\n/**\n * The options for a CommandKit plugin.\n */\nexport type PluginOptions = Record<string, any>;\n\n/**\n * Enum representing the type of plugin.\n * - Compiler: A plugin that runs at compile time.\n * - Runtime: A plugin that runs at runtime.\n */\nexport enum PluginType {\n Compiler = 'compiler',\n Runtime = 'runtime',\n}\n\n/**\n * Base class for CommandKit plugins.\n */\nexport abstract class PluginCommon<\n T extends PluginOptions = PluginOptions,\n C extends CommonPluginRuntime = CommonPluginRuntime,\n> {\n /**\n * The type of the plugin, either Compiler or Runtime.\n */\n public abstract readonly type: PluginType;\n /**\n * Unique identifier for the plugin instance.\n */\n public readonly id = randomUUID();\n /**\n * The time when the plugin was loaded, in milliseconds since the Unix epoch.\n */\n public readonly loadedAt = Date.now();\n /**\n * The name of the plugin.\n */\n public abstract readonly name: string;\n\n /**\n * Creates a new instance of the plugin.\n */\n public constructor(protected readonly options: T) {}\n\n /**\n * Called when this plugin is activated\n */\n public async activate(ctx: C): Promise<void> {}\n\n /**\n * Called when this plugin is deactivated\n */\n public async deactivate(ctx: C): Promise<void> {}\n}\n\n/**\n * Whether the given object is a CommandKit plugin.\n * @param plugin The object to check.\n * @returns Boolean indicating whether the object is a plugin.\n */\nexport function isPlugin(\n plugin: unknown,\n): plugin is PluginCommon<PluginOptions> {\n return plugin instanceof PluginCommon;\n}\n"],"mappings":";;;;;;;;;AAaA,IAAY,aAAL;CACL;CACA;;AACF;;;;AAKA,IAAsB,eAAtB,MAGE;CAqBsC;;;;CAbtC,AAAgB,SAAKA,wBAAW;;;;CAIhC,AAAgB,WAAW,KAAK,IAAI;;;;CASpC,AAAO,YAAY,AAAmB,SAAY;EAAZ;CAAa;;;;CAKnD,MAAa,SAAS,KAAuB,CAAC;;;;CAK9C,MAAa,WAAW,KAAuB,CAAC;AAClD;;;;;;AAOA,SAAgB,SACd,QACuC;CACvC,OAAO,kBAAkB;AAC3B"}
@@ -1,2 +1,2 @@
1
- import { $ as RuntimePlugin, et as isRuntimePlugin } from "../analytics-engine-Bz1p7ud3.js";
1
+ import { $ as RuntimePlugin, et as isRuntimePlugin } from "../analytics-engine-uY6FDAEv.js";
2
2
  export { RuntimePlugin, isRuntimePlugin };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_plugins_PluginCommon = require('./PluginCommon.js');
2
+ const require_plugins_PluginCommon = require("./PluginCommon.js");
3
3
 
4
4
  //#region src/plugins/RuntimePlugin.ts
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"RuntimePlugin.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"RuntimePlugin.js","names":["PluginCommon","isPlugin"],"sources":["../../src/plugins/RuntimePlugin.ts"],"sourcesContent":["import { Interaction, Message } from 'discord.js';\nimport {\n isPlugin,\n PluginCommon,\n PluginOptions,\n PluginType,\n} from './PluginCommon';\nimport type { CommandKitPluginRuntime } from './plugin-runtime/CommandKitPluginRuntime';\nimport { CommandBuilderLike, PreparedAppCommandExecution } from '../app';\nimport { CommandKitEnvironment } from '../context/environment';\nimport { CommandKitHMREvent } from '../utils/dev-hooks';\nimport { PreRegisterCommandsEvent } from '../app/register/CommandRegistrar';\nimport { CommandKitEventDispatch } from './types';\n\n/**\n * CommandKit plugin that runs at the runtime.\n */\nexport abstract class RuntimePlugin<\n T extends PluginOptions = PluginOptions,\n> extends PluginCommon<T, CommandKitPluginRuntime> {\n public readonly type = PluginType.Runtime;\n public readonly preload = new Set<string>();\n\n /**\n * Called before commands are loaded\n */\n public async onBeforeCommandsLoad(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called after commands are loaded\n */\n public async onAfterCommandsLoad(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called before events are loaded\n */\n public async onBeforeEventsLoad(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called after events are loaded\n */\n public async onAfterEventsLoad(ctx: CommandKitPluginRuntime): Promise<void> {}\n\n /**\n * Called before the client logs in\n */\n public async onBeforeClientLogin(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called after the client logs in\n */\n public async onAfterClientLogin(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called before interaction is handled\n * @param interaction The interaction\n */\n public async onBeforeInteraction(\n ctx: CommandKitPluginRuntime,\n interaction: Interaction,\n ): Promise<void> {}\n\n /**\n * Called before message command is processed\n * @param message The message\n */\n public async onBeforeMessageCommand(\n ctx: CommandKitPluginRuntime,\n message: Message,\n ): Promise<void> {}\n\n /**\n * Called before command is executed. This method can execute the command itself.\n * @param source The source that triggered the command\n * @param command The command\n * @param execute The function that executes the command\n */\n public async executeCommand(\n ctx: CommandKitPluginRuntime,\n env: CommandKitEnvironment,\n source: Interaction | Message,\n command: PreparedAppCommandExecution,\n execute: () => Promise<any>,\n ): Promise<boolean> {\n return false;\n }\n\n /**\n * Called after events router is initialized\n * @param ctx The context\n */\n public async onEventsRouterInit(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called after commands router is initialized\n * @param ctx The context\n */\n public async onCommandsRouterInit(\n ctx: CommandKitPluginRuntime,\n ): Promise<void> {}\n\n /**\n * Called when HMR event is received\n * @param ctx The context\n * @param event The event\n */\n public async performHMR(\n ctx: CommandKitPluginRuntime,\n event: CommandKitHMREvent,\n ): Promise<void> {}\n\n /**\n * Called before command is loaded for registration. This method can be used to modify the command data before it is loaded.\n * @param ctx The context\n * @param commands The command that is being loaded. This is a CommandBuilderLike object which represents Discord's command\n */\n async prepareCommand(\n ctx: CommandKitPluginRuntime,\n commands: CommandBuilderLike,\n ): Promise<CommandBuilderLike | null> {\n return null;\n }\n\n /**\n * Called before command is registered to discord. This method can cancel the registration of the command and handle it manually.\n * @param ctx The context\n * @param data The command registration data\n */\n async onBeforeRegisterCommands(\n ctx: CommandKitPluginRuntime,\n event: PreRegisterCommandsEvent,\n ): Promise<void> {}\n\n /**\n * Called before global commands registration. This method can cancel the registration of the command and handle it manually.\n * This method is called after `onBeforeRegisterCommands` if that stage was not handled.\n * @param ctx The context\n * @param event The command registration data\n */\n async onBeforeRegisterGlobalCommands(\n ctx: CommandKitPluginRuntime,\n event: PreRegisterCommandsEvent,\n ): Promise<void> {}\n\n /**\n * Called before guild commands registration. This method can cancel the registration of the command and handle it manually.\n * This method is called before guilds of the command are resolved. It is called after `onBeforeRegisterCommands` if that stage was not handled.\n * @param ctx The context\n * @param event The command registration data\n */\n async onBeforePrepareGuildCommandsRegistration(\n ctx: CommandKitPluginRuntime,\n event: PreRegisterCommandsEvent,\n ): Promise<void> {}\n\n /**\n * Called before guild commands registration. This method can cancel the registration of the command and handle it manually.\n * This method is called after guilds of the command are resolved. It is called after `onBeforePrepareGuildCommandsRegistration` if that stage was not handled.\n * @param ctx The context\n * @param event The command registration data\n */\n async onBeforeRegisterGuildCommands(\n ctx: CommandKitPluginRuntime,\n event: PreRegisterCommandsEvent,\n ): Promise<void> {}\n\n /**\n * Called after command and all of its deferred functions are executed.\n * @param ctx The context\n * @param env The environment of the command. This environment contains the command execution data such as command context and more.\n */\n async onAfterCommand(\n ctx: CommandKitPluginRuntime,\n env: CommandKitEnvironment,\n ) {}\n\n /**\n * Called before emitting an event\n * @param ctx The context\n * @param event The event that is being emitted\n */\n public async willEmitEvent(\n ctx: CommandKitPluginRuntime,\n event: CommandKitEventDispatch,\n ) {}\n}\n\nexport function isRuntimePlugin(plugin: unknown): plugin is RuntimePlugin {\n return (\n plugin instanceof RuntimePlugin ||\n (isPlugin(plugin) && plugin.type === PluginType.Runtime)\n );\n}\n"],"mappings":";;;;;;;AAiBA,IAAsB,gBAAtB,cAEUA,0CAAyC;CACjD,AAAgB;CAChB,AAAgB,0BAAU,IAAI,IAAY;;;;CAK1C,MAAa,qBACX,KACe,CAAC;;;;CAKlB,MAAa,oBACX,KACe,CAAC;;;;CAKlB,MAAa,mBACX,KACe,CAAC;;;;CAKlB,MAAa,kBAAkB,KAA6C,CAAC;;;;CAK7E,MAAa,oBACX,KACe,CAAC;;;;CAKlB,MAAa,mBACX,KACe,CAAC;;;;;CAMlB,MAAa,oBACX,KACA,aACe,CAAC;;;;;CAMlB,MAAa,uBACX,KACA,SACe,CAAC;;;;;;;CAQlB,MAAa,eACX,KACA,KACA,QACA,SACA,SACkB;EAClB,OAAO;CACT;;;;;CAMA,MAAa,mBACX,KACe,CAAC;;;;;CAMlB,MAAa,qBACX,KACe,CAAC;;;;;;CAOlB,MAAa,WACX,KACA,OACe,CAAC;;;;;;CAOlB,MAAM,eACJ,KACA,UACoC;EACpC,OAAO;CACT;;;;;;CAOA,MAAM,yBACJ,KACA,OACe,CAAC;;;;;;;CAQlB,MAAM,+BACJ,KACA,OACe,CAAC;;;;;;;CAQlB,MAAM,yCACJ,KACA,OACe,CAAC;;;;;;;CAQlB,MAAM,8BACJ,KACA,OACe,CAAC;;;;;;CAOlB,MAAM,eACJ,KACA,KACA,CAAC;;;;;;CAOH,MAAa,cACX,KACA,OACA,CAAC;AACL;AAEA,SAAgB,gBAAgB,QAA0C;CACxE,OACE,kBAAkB,iBACjBC,sCAAS,MAAM,KAAK,OAAO;AAEhC"}
@@ -1,2 +1,2 @@
1
- import { $ as RuntimePlugin, G as CompilerPlugin, H as CompilerPluginRuntime, I as CommandKitPluginRuntime, J as isCompilerPlugin, K as PluginTransformParameters, Q as TemplateHandler, U as CommonDirectiveTransformer, V as CommonPluginRuntime, W as CommonDirectiveTransformerOptions, X as CommandKitPlugin, Y as CommandKitEventDispatch, Z as MaybeFalsey, et as isRuntimePlugin, q as TransformedResult } from "../analytics-engine-Bz1p7ud3.js";
1
+ import { $ as RuntimePlugin, G as CompilerPlugin, H as CompilerPluginRuntime, I as CommandKitPluginRuntime, J as isCompilerPlugin, K as PluginTransformParameters, Q as TemplateHandler, U as CommonDirectiveTransformer, V as CommonPluginRuntime, W as CommonDirectiveTransformerOptions, X as CommandKitPlugin, Y as CommandKitEventDispatch, Z as MaybeFalsey, et as isRuntimePlugin, q as TransformedResult } from "../analytics-engine-uY6FDAEv.js";
2
2
  export { CommandKitEventDispatch, CommandKitPlugin, CommandKitPluginRuntime, CommonDirectiveTransformer, CommonDirectiveTransformerOptions, CommonPluginRuntime, CompilerPlugin, CompilerPluginRuntime, MaybeFalsey, PluginTransformParameters, RuntimePlugin, TemplateHandler, TransformedResult, isCompilerPlugin, isRuntimePlugin };
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../commandkit-gJ4YjTy4.js');
3
- const require_plugins_CompilerPlugin = require('./CompilerPlugin.js');
4
- const require_plugins_RuntimePlugin = require('./RuntimePlugin.js');
2
+ const require_commandkit = require("../commandkit-CzNV2oE8.js");
3
+ const require_plugins_CompilerPlugin = require("./CompilerPlugin.js");
4
+ const require_plugins_RuntimePlugin = require("./RuntimePlugin.js");
5
5
 
6
6
  exports.CommandKitPluginRuntime = require_commandkit.CommandKitPluginRuntime;
7
7
  exports.CommonDirectiveTransformer = require_commandkit.CommonDirectiveTransformer;
@@ -1,2 +1,2 @@
1
- import { I as CommandKitPluginRuntime } from "../../analytics-engine-Bz1p7ud3.js";
1
+ import { I as CommandKitPluginRuntime } from "../../analytics-engine-uY6FDAEv.js";
2
2
  export { CommandKitPluginRuntime };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.CommandKitPluginRuntime = require_commandkit.CommandKitPluginRuntime;
@@ -1,2 +1,2 @@
1
- import { H as CompilerPluginRuntime } from "../../analytics-engine-Bz1p7ud3.js";
1
+ import { H as CompilerPluginRuntime } from "../../analytics-engine-uY6FDAEv.js";
2
2
  export { CompilerPluginRuntime };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.CompilerPluginRuntime = require_commandkit.CompilerPluginRuntime;
@@ -1,2 +1,2 @@
1
- import { U as CommonDirectiveTransformer, W as CommonDirectiveTransformerOptions } from "../../../analytics-engine-Bz1p7ud3.js";
1
+ import { U as CommonDirectiveTransformer, W as CommonDirectiveTransformerOptions } from "../../../analytics-engine-uY6FDAEv.js";
2
2
  export { CommonDirectiveTransformer, CommonDirectiveTransformerOptions };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../../../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../../../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.CommonDirectiveTransformer = require_commandkit.CommonDirectiveTransformer;
@@ -1,4 +1,4 @@
1
- import { G as CompilerPlugin, K as PluginTransformParameters, Z as MaybeFalsey, q as TransformedResult } from "../../../analytics-engine-Bz1p7ud3.js";
1
+ import { G as CompilerPlugin, K as PluginTransformParameters, Z as MaybeFalsey, q as TransformedResult } from "../../../analytics-engine-uY6FDAEv.js";
2
2
  //#region src/plugins/plugin-runtime/builtin/MacroPlugin.d.ts
3
3
  /**
4
4
  * Macro plugin enables the use of `"use macro"` directive in the code.
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../../../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../../../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.MacroPlugin = require_commandkit.MacroPlugin;
@@ -1,2 +1,2 @@
1
- import { V as CommonPluginRuntime } from "../../analytics-engine-Bz1p7ud3.js";
1
+ import { V as CommonPluginRuntime } from "../../analytics-engine-uY6FDAEv.js";
2
2
  export { CommonPluginRuntime };
@@ -1 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
@@ -1,2 +1,2 @@
1
- import { Q as TemplateHandler, X as CommandKitPlugin, Y as CommandKitEventDispatch, Z as MaybeFalsey } from "../analytics-engine-Bz1p7ud3.js";
1
+ import { Q as TemplateHandler, X as CommandKitPlugin, Y as CommandKitEventDispatch, Z as MaybeFalsey } from "../analytics-engine-uY6FDAEv.js";
2
2
  export { CommandKitEventDispatch, CommandKitPlugin, MaybeFalsey, TemplateHandler };
@@ -1 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
@@ -19,14 +19,13 @@ var __copyProps = (to, from, except, desc) => {
19
19
  }
20
20
  return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
23
23
  value: mod,
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
-
29
- Object.defineProperty(exports, '__toESM', {
28
+ Object.defineProperty(exports, "__toESM", {
30
29
  enumerable: true,
31
30
  get: function () {
32
31
  return __toESM;
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { _n as EventHandler, fn as CommandContext, gn as CommandMetadataFunction, hn as CommandMetadata, mn as CommandKitOptions, pn as CommandData } from "./analytics-engine-Bz1p7ud3.js";
1
+ import { _n as EventHandler, fn as CommandContext, gn as CommandMetadataFunction, hn as CommandMetadata, mn as CommandKitOptions, pn as CommandData } from "./analytics-engine-uY6FDAEv.js";
2
2
  export { CommandContext, CommandData, CommandKitOptions, CommandMetadata, CommandMetadataFunction, EventHandler };
package/dist/types.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
@@ -1 +1 @@
1
- {"version":3,"file":"colors.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"colors.js","names":["createColors"],"sources":["../../src/utils/colors.ts"],"sourcesContent":["import { createColors } from 'picocolors';\n\nexport default createColors(true);\n"],"mappings":";;;;AAEA,yBAAeA,yBAAa,IAAI"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/constants.ts
4
3
  /**
5
4
  * The current working directory of the CommandKit instance.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../src/utils/constants.ts"],"sourcesContent":["/**\n * The current working directory of the CommandKit instance.\n */\nexport const COMMANDKIT_CWD = process.env.COMMANDKIT_CWD || process.cwd();\n\n/**\n * Indicates whether CommandKit is running in development mode.\n */\nexport const COMMANDKIT_IS_DEV = process.env.COMMANDKIT_IS_DEV === 'true';\n\n/**\n * Indicates whether CommandKit is running in CLI thread.\n */\nexport const COMMANDKIT_IS_CLI = process.env.COMMANDKIT_IS_CLI === 'true';\n\n/**\n * Indicates whether CommandKit is running in test mode.\n */\nexport const COMMANDKIT_IS_TEST = process.env.COMMANDKIT_IS_TEST === 'true';\n\n/**\n * Indicates that CommandKit is running in a build-like environment.\n * @private\n * @internal\n */\nexport function isBuildLikeEnvironment() {\n const isCLI = process.env.COMMANDKIT_INTERNAL_IS_CLI_PROCESS === 'true';\n if (isCLI) return true;\n\n return process.env.COMMANDKIT_IS_BUILD === 'true';\n}\n\n/**\n * The current bootstrap mode of CommandKit.\n * This can be 'development' or 'production'.\n */\nexport const COMMANDKIT_BOOTSTRAP_MODE = (process.env\n .COMMANDKIT_BOOTSTRAP_MODE || 'development') as 'development' | 'production';\n\n/**\n * Types of Hot Module Replacement events\n */\nexport const HMREventType = {\n /**\n * HMR event for reloading commands.\n */\n ReloadCommands: 'reload-commands',\n /**\n * HMR event for reloading events.\n */\n ReloadEvents: 'reload-events',\n /**\n * HMR event for reloading unknown path, typically used by the plugins.\n */\n Unknown: 'unknown',\n} as const;\n\n/**\n * File system change types delivered through HMR messages.\n */\nexport const HMREventChangeType = {\n Add: 'add',\n Change: 'change',\n Unlink: 'unlink',\n UnlinkDir: 'unlinkDir',\n} as const;\n\n/**\n * The type for HMR events.\n */\nexport type HMREventType = (typeof HMREventType)[keyof typeof HMREventType];\n\n/**\n * The type for file change events in HMR payloads.\n */\nexport type HMREventChangeType =\n (typeof HMREventChangeType)[keyof typeof HMREventChangeType];\n"],"mappings":";;;;;AAGA,MAAa,iBAAiB,QAAQ,IAAI,kBAAkB,QAAQ,IAAI;;;;AAKxE,MAAa,oBAAoB,QAAQ,IAAI,sBAAsB;;;;AAKnE,MAAa,oBAAoB,QAAQ,IAAI,sBAAsB;;;;AAKnE,MAAa,qBAAqB,QAAQ,IAAI,uBAAuB;;;;;;AAOrE,SAAgB,yBAAyB;CAEvC,IADc,QAAQ,IAAI,uCAAuC,QACtD,OAAO;CAElB,OAAO,QAAQ,IAAI,wBAAwB;AAC7C;;;;;AAMA,MAAa,4BAA6B,QAAQ,IAC/C,6BAA6B;;;;AAKhC,MAAa,eAAe;;;;CAI1B,gBAAgB;;;;CAIhB,cAAc;;;;CAId,SAAS;AACX;;;;AAKA,MAAa,qBAAqB;CAChC,KAAK;CACL,QAAQ;CACR,QAAQ;CACR,WAAW;AACb"}
@@ -1,2 +1,2 @@
1
- import { nt as IpcMessageCommand, rt as registerDevHooks, tt as CommandKitHMREvent } from "../analytics-engine-Bz1p7ud3.js";
1
+ import { nt as IpcMessageCommand, rt as registerDevHooks, tt as CommandKitHMREvent } from "../analytics-engine-uY6FDAEv.js";
2
2
  export { CommandKitHMREvent, IpcMessageCommand, registerDevHooks };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_commandkit = require('../commandkit-gJ4YjTy4.js');
2
+ const require_commandkit = require("../commandkit-CzNV2oE8.js");
3
3
 
4
4
  exports.registerDevHooks = require_commandkit.registerDevHooks;
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/error-codes.ts
4
3
  /**
5
4
  * The error codes used by CommandKit.
@@ -1 +1 @@
1
- {"version":3,"file":"error-codes.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"error-codes.js","names":[],"sources":["../../src/utils/error-codes.ts"],"sourcesContent":["/**\n * The error codes used by CommandKit.\n */\nexport const CommandKitErrorCodes = {\n /**\n * Error code for exiting middleware.\n */\n StopMiddlewares: Symbol('kStopMiddlewares'),\n /**\n * Error code for forwarded commands.\n */\n ForwardedCommand: Symbol('kForwardedCommand'),\n /**\n * Error code for invalid command prefix.\n */\n InvalidCommandPrefix: Symbol('kInvalidCommandPrefix'),\n /**\n * Error code for plugin capture handle.\n */\n PluginCaptureHandle: Symbol('kPluginCaptureHandle'),\n /**\n * Error code for event interruption signal\n */\n StopEvents: Symbol('kStopEvents'),\n} as const;\n\n/**\n * The type for CommandKit errors.\n */\nexport type CommandKitError = Error & { code: symbol };\n\n/**\n * Creates a new CommandKit error with the specified code.\n * @param code The error code to assign to the error.\n * @returns A new CommandKit error instance.\n */\nexport function createCommandKitError(code: symbol): CommandKitError {\n const error = new Error() as CommandKitError;\n\n Reflect.set(error, 'code', code);\n\n return error;\n}\n\n/**\n * Checks if the given error is a CommandKit error.\n * @param error The error to check.\n * @returns True if the error is a CommandKit error, false otherwise.\n */\nexport function isCommandKitError(error: unknown): error is CommandKitError {\n if (!(error instanceof Error)) return false;\n const code = Reflect.get(error, 'code');\n\n for (const key in CommandKitErrorCodes) {\n if (CommandKitErrorCodes[key as keyof typeof CommandKitErrorCodes] === code)\n return true;\n }\n\n return false;\n}\n\n/**\n * Checks if the given error is of a specific CommandKit error type.\n * @param error The error to check.\n * @param code The error code or an array of error codes to check against.\n * @returns True if the error matches the specified code(s), false otherwise.\n */\nexport function isErrorType(error: unknown, code: symbol | symbol[]): boolean {\n if (!isCommandKitError(error)) return false;\n const errorCode = Reflect.get(error, 'code');\n\n if (!errorCode) return false;\n\n if (Array.isArray(code)) return code.includes(errorCode);\n\n return errorCode === code;\n}\n"],"mappings":";;;;;AAGA,MAAa,uBAAuB;;;;CAIlC,iBAAiB,OAAO,kBAAkB;;;;CAI1C,kBAAkB,OAAO,mBAAmB;;;;CAI5C,sBAAsB,OAAO,uBAAuB;;;;CAIpD,qBAAqB,OAAO,sBAAsB;;;;CAIlD,YAAY,OAAO,aAAa;AAClC;;;;;;AAYA,SAAgB,sBAAsB,MAA+B;CACnE,MAAM,wBAAQ,IAAI,MAAM;CAExB,QAAQ,IAAI,OAAO,QAAQ,IAAI;CAE/B,OAAO;AACT;;;;;;AAOA,SAAgB,kBAAkB,OAA0C;CAC1E,IAAI,EAAE,iBAAiB,QAAQ,OAAO;CACtC,MAAM,OAAO,QAAQ,IAAI,OAAO,MAAM;CAEtC,KAAK,MAAM,OAAO,sBAChB,IAAI,qBAAqB,SAA8C,MACrE,OAAO;CAGX,OAAO;AACT;;;;;;;AAQA,SAAgB,YAAY,OAAgB,MAAkC;CAC5E,IAAI,CAAC,kBAAkB,KAAK,GAAG,OAAO;CACtC,MAAM,YAAY,QAAQ,IAAI,OAAO,MAAM;CAE3C,IAAI,CAAC,WAAW,OAAO;CAEvB,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,SAAS,SAAS;CAEvD,OAAO,cAAc;AACvB"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_rolldown_runtime = require('../rolldown-runtime-C_NdSu1c.js');
2
+ const require_rolldown_runtime = require("../rolldown-runtime-AN5ru5iW.js");
3
3
  let path = require("path");
4
4
  path = require_rolldown_runtime.__toESM(path);
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-file-url.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"resolve-file-url.js","names":[],"sources":["../../src/utils/resolve-file-url.ts"],"sourcesContent":["import path from 'path';\n\n/**\n * Convert a local file path to a file URL.\n * @param filePath - The local file's path.\n * @param withTs - Whether to append a timestamp to the URL.\n * @returns - The converted file URL.\n */\nexport function toFileURL(filePath: string, withTs = false) {\n const resolvedPath = path.resolve(filePath);\n return `${'file://' + resolvedPath.replace(/\\\\\\\\|\\\\/g, '/')}${withTs ? `?ts=${Date.now()}` : ''}`;\n}\n"],"mappings":";;;;;;;;;;;;AAQA,SAAgB,UAAU,UAAkB,SAAS,OAAO;CAE1D,OAAO,GAAG,YADW,aAAK,QAAQ,QACD,CAAC,CAAC,QAAQ,YAAY,GAAG,IAAI,SAAS,OAAO,KAAK,IAAI,MAAM;AAC/F"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_utils_constants = require('./constants.js');
2
+ const require_utils_constants = require("./constants.js");
3
3
  let node_fs = require("node:fs");
4
4
  let node_path = require("node:path");
5
5
  let node_fs_promises = require("node:fs/promises");
@@ -15,7 +15,8 @@ function getEnvFilePath() {
15
15
  return (0, node_path.join)(require_utils_constants.COMMANDKIT_CWD, COMMANDKIT_ENV_FILE);
16
16
  }
17
17
  async function ensureCommandkitEnvFile() {
18
- await (0, node_fs_promises.writeFile)(getEnvFilePath(), `/// <reference path="./${COMMANDKIT_TYPES_DIRECTORY}/types" />\n`, "utf8");
18
+ const envPath = getEnvFilePath();
19
+ await (0, node_fs_promises.writeFile)(envPath, `/// <reference path="./${COMMANDKIT_TYPES_DIRECTORY}/types" />\n`, "utf8");
19
20
  }
20
21
  async function writeTypesContent(names = []) {
21
22
  const typesPath = getTypesFilePath();
@@ -1 +1 @@
1
- {"version":3,"file":"types-package.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"types-package.js","names":["join","COMMANDKIT_CWD","writeFile","mkdir","dirname","COMMANDKIT_IS_DEV","existsSync"],"sources":["../../src/utils/types-package.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { COMMANDKIT_CWD, COMMANDKIT_IS_DEV } from './constants';\nimport { existsSync } from 'node:fs';\n\nexport const COMMANDKIT_TYPES_DIRECTORY = '.commandkit';\nexport const COMMANDKIT_TYPES_FILE = 'types.ts';\nexport const COMMANDKIT_ENV_FILE = 'commandkit-env.d.ts';\n\nexport function getTypesFilePath() {\n return join(\n COMMANDKIT_CWD,\n COMMANDKIT_TYPES_DIRECTORY,\n COMMANDKIT_TYPES_FILE,\n );\n}\n\nfunction getEnvFilePath() {\n return join(COMMANDKIT_CWD, COMMANDKIT_ENV_FILE);\n}\n\nasync function ensureCommandkitEnvFile() {\n const envPath = getEnvFilePath();\n const content = `/// <reference path=\"./${COMMANDKIT_TYPES_DIRECTORY}/types\" />\\n`;\n await writeFile(envPath, content, 'utf8');\n}\n\nasync function writeTypesContent(names: string[] = []) {\n const typesPath = getTypesFilePath();\n\n const entryLines = names\n .sort((a, b) => a.localeCompare(b))\n .map((name) => ` ${JSON.stringify(name)}: true;`)\n .join('\\n');\n\n const registryBody = entryLines || ' __commandkit_wide__: true;';\n\n const declaration = `// Auto-generated by CommandKit\\nexport {};\\ndeclare global {\\n namespace CommandKitTypes {\\n interface Registry {\\n${registryBody}\\n }\\n }\\n}\\n`;\n\n await mkdir(dirname(typesPath), { recursive: true }).catch(() => {});\n await writeFile(typesPath, declaration, 'utf8');\n\n return typesPath;\n}\n\n/**\n * @private\n */\nexport async function generateTypesPackage(force = false) {\n const location = getTypesFilePath();\n if (!COMMANDKIT_IS_DEV && !force) return location;\n\n await writeTypesContent();\n await ensureCommandkitEnvFile();\n\n return location;\n}\n\n/**\n * @private\n */\nexport async function rewriteCommandDeclaration(data: string[] | string) {\n const type = getTypesFilePath();\n\n if (!existsSync(dirname(type))) {\n await mkdir(dirname(type), { recursive: true }).catch(() => {});\n }\n\n const names = Array.isArray(data)\n ? data\n : data\n .replace(/type\\s+CommandTypeData\\s*=\\s*/g, '')\n .split('|')\n .map((part) => part.trim().replace(/^\"|\"$/g, ''))\n .filter(Boolean)\n .filter((part) => part !== 'string');\n\n const dedupedNames = Array.from(new Set(names));\n\n await writeTypesContent(dedupedNames);\n await ensureCommandkitEnvFile();\n}\n"],"mappings":";;;;;;;AAKA,MAAa,6BAA6B;AAC1C,MAAa,wBAAwB;AACrC,MAAa,sBAAsB;AAEnC,SAAgB,mBAAmB;CACjC,WAAOA,gBACLC,wCACA,4BACA,qBACF;AACF;AAEA,SAAS,iBAAiB;CACxB,WAAOD,gBAAKC,wCAAgB,mBAAmB;AACjD;AAEA,eAAe,0BAA0B;CACvC,MAAM,UAAU,eAAe;CAE/B,UAAMC,4BAAU,SAAS,0BADiB,2BAA2B,eACnC,MAAM;AAC1C;AAEA,eAAe,kBAAkB,QAAkB,CAAC,GAAG;CACrD,MAAM,YAAY,iBAAiB;CASnC,MAAM,cAAc,2HAPD,MAChB,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAClC,KAAK,SAAS,OAAO,KAAK,UAAU,IAAI,EAAE,QAAQ,CAAC,CACnD,KAAK,IAEsB,KAAK,iCAEyH;CAE5J,UAAMC,4BAAMC,mBAAQ,SAAS,GAAG,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;CACnE,UAAMF,4BAAU,WAAW,aAAa,MAAM;CAE9C,OAAO;AACT;;;;AAKA,eAAsB,qBAAqB,QAAQ,OAAO;CACxD,MAAM,WAAW,iBAAiB;CAClC,IAAI,CAACG,6CAAqB,CAAC,OAAO,OAAO;CAEzC,MAAM,kBAAkB;CACxB,MAAM,wBAAwB;CAE9B,OAAO;AACT;;;;AAKA,eAAsB,0BAA0B,MAAyB;CACvE,MAAM,OAAO,iBAAiB;CAE9B,IAAI,KAACC,wBAAWF,mBAAQ,IAAI,CAAC,GAC3B,UAAMD,4BAAMC,mBAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;CAGhE,MAAM,QAAQ,MAAM,QAAQ,IAAI,IAC5B,OACA,KACG,QAAQ,kCAAkC,EAAE,CAAC,CAC7C,MAAM,GAAG,CAAC,CACV,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,QAAQ,UAAU,EAAE,CAAC,CAAC,CAChD,OAAO,OAAO,CAAC,CACf,QAAQ,SAAS,SAAS,QAAQ;CAIzC,MAAM,kBAFe,MAAM,KAAK,IAAI,IAAI,KAAK,CAEV,CAAC;CACpC,MAAM,wBAAwB;AAChC"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/useful-stuff/async-queue.ts
4
3
  var AsyncQueue = class {
5
4
  concurrency;
@@ -1 +1 @@
1
- {"version":3,"file":"async-queue.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"async-queue.js","names":[],"sources":["../../../src/utils/useful-stuff/async-queue.ts"],"sourcesContent":["/**\n * Async queue implementation for processing tasks sequentially or with limited concurrency.\n * Useful for rate-limiting, batching, or controlling resource usage.\n */\n\nexport interface AsyncQueueOptions {\n /** Maximum number of concurrent tasks. Default: 1 (sequential) */\n concurrency?: number;\n /** Optional callback invoked when all tasks are completed */\n onDrain?: () => void | Promise<void>;\n /** Optional AbortSignal for cancelling the queue */\n signal?: AbortSignal;\n}\n\nexport type AsyncQueueTask<T> = () => Promise<T>;\n\nexport class AsyncQueue {\n private readonly concurrency: number;\n private readonly onDrain?: () => void | Promise<void>;\n private readonly signal?: AbortSignal;\n private running = 0;\n private paused = false;\n private aborted = false;\n private queue: Array<() => void> = [];\n\n constructor(options: AsyncQueueOptions = {}) {\n this.concurrency = options.concurrency ?? 1;\n this.onDrain = options.onDrain;\n this.signal = options.signal;\n\n if (this.signal) {\n this.signal.addEventListener('abort', () => {\n this.abort();\n });\n }\n }\n\n /**\n * Adds a task to the queue.\n * @param task - The async function to execute.\n * @param signal - Optional AbortSignal for cancelling this specific task.\n * @returns Promise resolving to the result of the task.\n */\n public add<T>(task: AsyncQueueTask<T>, signal?: AbortSignal): Promise<T> {\n if (this.aborted) {\n return Promise.reject(new Error('Queue has been aborted'));\n }\n\n return new Promise<T>((resolve, reject) => {\n const run = async () => {\n if (this.paused || this.aborted) {\n if (this.aborted) {\n reject(new Error('Queue has been aborted'));\n } else {\n this.queue.push(run);\n }\n return;\n }\n\n // Check if task-specific signal is aborted\n if (signal?.aborted) {\n reject(new Error('Task was aborted'));\n return;\n }\n\n this.running++;\n try {\n const result = await task();\n resolve(result);\n } catch (err) {\n reject(err);\n } finally {\n this.running--;\n this.next();\n }\n };\n\n if (this.running < this.concurrency && !this.paused && !this.aborted) {\n run();\n } else {\n this.queue.push(run);\n }\n });\n }\n\n /**\n * Pauses the queue. No new tasks will be started until resumed.\n */\n public pause() {\n this.paused = true;\n }\n\n /**\n * Resumes the queue and processes pending tasks.\n */\n public resume() {\n if (!this.paused) return;\n this.paused = false;\n this.next();\n }\n\n /**\n * Aborts the queue, rejecting all pending tasks.\n */\n public abort() {\n this.aborted = true;\n this.clear();\n }\n\n /**\n * Clears all pending tasks from the queue.\n */\n public clear() {\n this.queue = [];\n }\n\n /**\n * Returns the number of running tasks.\n */\n public getRunning(): number {\n return this.running;\n }\n\n /**\n * Returns the number of pending tasks in the queue.\n */\n public getPending(): number {\n return this.queue.length;\n }\n\n /**\n * Returns true if the queue is currently paused.\n */\n public isPaused(): boolean {\n return this.paused;\n }\n\n /**\n * Returns true if the queue has been aborted.\n */\n public isAborted(): boolean {\n return this.aborted;\n }\n\n private next() {\n if (this.paused || this.aborted) return;\n while (this.running < this.concurrency && this.queue.length > 0) {\n const fn = this.queue.shift();\n if (fn) fn();\n }\n if (this.running === 0 && this.queue.length === 0 && this.onDrain) {\n this.onDrain();\n }\n }\n}\n\n/**\n * Creates a new async queue instance with the specified configuration.\n * @param options - Configuration options for the async queue.\n * @returns New AsyncQueue instance.\n *\n * @example\n * ```typescript\n * const controller = new AbortController();\n * const queue = createAsyncQueue({\n * concurrency: 2,\n * signal: controller.signal\n * });\n * queue.add(async () => await doSomething());\n * controller.abort(); // Aborts the queue\n * ```\n */\nexport function createAsyncQueue(options?: AsyncQueueOptions): AsyncQueue {\n return new AsyncQueue(options);\n}\n"],"mappings":";;AAgBA,IAAa,aAAb,MAAwB;CACtB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,UAAU;CAClB,AAAQ,SAAS;CACjB,AAAQ,UAAU;CAClB,AAAQ,QAA2B,CAAC;CAEpC,YAAY,UAA6B,CAAC,GAAG;EAC3C,KAAK,cAAc,QAAQ,eAAe;EAC1C,KAAK,UAAU,QAAQ;EACvB,KAAK,SAAS,QAAQ;EAEtB,IAAI,KAAK,QACP,KAAK,OAAO,iBAAiB,eAAe;GAC1C,KAAK,MAAM;EACb,CAAC;CAEL;;;;;;;CAQA,AAAO,IAAO,MAAyB,QAAkC;EACvE,IAAI,KAAK,SACP,OAAO,QAAQ,uBAAO,IAAI,MAAM,wBAAwB,CAAC;EAG3D,OAAO,IAAI,SAAY,SAAS,WAAW;GACzC,MAAM,MAAM,YAAY;IACtB,IAAI,KAAK,UAAU,KAAK,SAAS;KAC/B,IAAI,KAAK,SACP,uBAAO,IAAI,MAAM,wBAAwB,CAAC;UAE1C,KAAK,MAAM,KAAK,GAAG;KAErB;IACF;IAGA,oDAAI,OAAQ,SAAS;KACnB,uBAAO,IAAI,MAAM,kBAAkB,CAAC;KACpC;IACF;IAEA,KAAK;IACL,IAAI;KAEF,QAAQ,MADa,KAAK,CACZ;IAChB,SAAS,KAAK;KACZ,OAAO,GAAG;IACZ,UAAU;KACR,KAAK;KACL,KAAK,KAAK;IACZ;GACF;GAEA,IAAI,KAAK,UAAU,KAAK,eAAe,CAAC,KAAK,UAAU,CAAC,KAAK,SAC3D,IAAI;QAEJ,KAAK,MAAM,KAAK,GAAG;EAEvB,CAAC;CACH;;;;CAKA,AAAO,QAAQ;EACb,KAAK,SAAS;CAChB;;;;CAKA,AAAO,SAAS;EACd,IAAI,CAAC,KAAK,QAAQ;EAClB,KAAK,SAAS;EACd,KAAK,KAAK;CACZ;;;;CAKA,AAAO,QAAQ;EACb,KAAK,UAAU;EACf,KAAK,MAAM;CACb;;;;CAKA,AAAO,QAAQ;EACb,KAAK,QAAQ,CAAC;CAChB;;;;CAKA,AAAO,aAAqB;EAC1B,OAAO,KAAK;CACd;;;;CAKA,AAAO,aAAqB;EAC1B,OAAO,KAAK,MAAM;CACpB;;;;CAKA,AAAO,WAAoB;EACzB,OAAO,KAAK;CACd;;;;CAKA,AAAO,YAAqB;EAC1B,OAAO,KAAK;CACd;CAEA,AAAQ,OAAO;EACb,IAAI,KAAK,UAAU,KAAK,SAAS;EACjC,OAAO,KAAK,UAAU,KAAK,eAAe,KAAK,MAAM,SAAS,GAAG;GAC/D,MAAM,KAAK,KAAK,MAAM,MAAM;GAC5B,IAAI,IAAI,GAAG;EACb;EACA,IAAI,KAAK,YAAY,KAAK,KAAK,MAAM,WAAW,KAAK,KAAK,SACxD,KAAK,QAAQ;CAEjB;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,iBAAiB,SAAyC;CACxE,OAAO,IAAI,WAAW,OAAO;AAC/B"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/useful-stuff/mutex.ts
4
3
  /**
5
4
  * In-memory storage implementation for mutex locks.
@@ -1 +1 @@
1
- {"version":3,"file":"mutex.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"mutex.js","names":[],"sources":["../../../src/utils/useful-stuff/mutex.ts"],"sourcesContent":["/**\n * Async mutex implementation for coordinating access to shared resources.\n * Provides mutual exclusion to ensure only one task can access a resource at a time.\n */\n\n/**\n * Interface for mutex storage implementations.\n * Provides methods to store, retrieve, and delete mutex lock data.\n */\nexport interface MutexStorage {\n /**\n * Attempts to acquire a lock for a given key\n * @param key - The unique identifier for the mutex lock\n * @param timeout - Optional timeout in milliseconds for the lock\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if lock was acquired, false if timeout or already locked\n */\n acquire(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<boolean>;\n\n /**\n * Releases the lock for a given key\n * @param key - The unique identifier for the mutex lock\n * @returns Promise that resolves when the lock is released\n */\n release(key: string): Promise<void>;\n\n /**\n * Checks if a lock is currently held for a given key\n * @param key - The unique identifier for the mutex lock\n * @returns Promise resolving to true if the lock is held, false otherwise\n */\n isLocked(key: string): Promise<boolean>;\n}\n\n/**\n * Configuration options for mutex\n */\nexport interface MutexOptions {\n /** Default timeout in milliseconds for lock acquisition. Default: 30000 */\n timeout?: number;\n /** Storage implementation for persisting mutex data. Default: {@link MemoryMutexStorage} */\n storage?: MutexStorage;\n}\n\n/**\n * In-memory storage implementation for mutex locks.\n * Suitable for single-instance applications.\n */\nexport class MemoryMutexStorage implements MutexStorage {\n private readonly locks = new Map<\n string,\n { holder: string; acquiredAt: number }\n >();\n\n /**\n * Attempts to acquire a lock for a given key\n * @param key - The unique identifier for the mutex lock\n * @param timeout - Optional timeout in milliseconds for the lock\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if lock was acquired, false if timeout or already locked\n */\n async acquire(\n key: string,\n timeout: number = 30000,\n signal?: AbortSignal,\n ): Promise<boolean> {\n const holder = this.generateHolderId();\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n // Check if aborted\n if (signal?.aborted) {\n throw new Error('Lock acquisition was aborted');\n }\n\n if (!this.locks.has(key)) {\n this.locks.set(key, { holder, acquiredAt: Date.now() });\n return true;\n }\n await this.delay(10);\n }\n\n return false;\n }\n\n /**\n * Releases the lock for a given key\n * @param key - The unique identifier for the mutex lock\n * @returns Promise that resolves when the lock is released\n */\n async release(key: string): Promise<void> {\n this.locks.delete(key);\n }\n\n /**\n * Checks if a lock is currently held for a given key\n * @param key - The unique identifier for the mutex lock\n * @returns Promise resolving to true if the lock is held, false otherwise\n */\n async isLocked(key: string): Promise<boolean> {\n return this.locks.has(key);\n }\n\n private generateHolderId(): string {\n return `holder_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n\n/**\n * Async mutex implementation that provides mutual exclusion for shared resources.\n * Ensures only one task can access a protected resource at a time.\n */\nexport class Mutex {\n private storage: MutexStorage;\n private readonly defaultTimeout: number;\n\n /**\n * Creates a new mutex instance\n * @param options - Configuration options for the mutex\n */\n public constructor(options: MutexOptions = {}) {\n this.storage = options.storage || new MemoryMutexStorage();\n this.defaultTimeout = options.timeout || 30000;\n }\n\n /**\n * Sets the storage implementation for the mutex\n * @param storage - The storage implementation to use\n */\n public setStorage(storage: MutexStorage) {\n this.storage = storage;\n }\n\n /**\n * Gets the storage implementation for the mutex\n * @returns The storage implementation\n */\n public getStorage(): MutexStorage {\n return this.storage;\n }\n\n /**\n * Acquires a lock for the given key\n * @param key - The unique identifier for the mutex lock\n * @param timeout - Optional timeout in milliseconds for lock acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if lock was acquired, false if timeout\n */\n public async acquire(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<boolean> {\n return this.storage.acquire(key, timeout || this.defaultTimeout, signal);\n }\n\n /**\n * Releases the lock for the given key\n * @param key - The unique identifier for the mutex lock\n * @returns Promise that resolves when the lock is released\n */\n public async release(key: string): Promise<void> {\n return this.storage.release(key);\n }\n\n /**\n * Checks if a lock is currently held for the given key\n * @param key - The unique identifier for the mutex lock\n * @returns Promise resolving to true if the lock is held, false otherwise\n */\n public async isLocked(key: string): Promise<boolean> {\n return this.storage.isLocked(key);\n }\n\n /**\n * Executes a function with exclusive access to the resource\n * @param key - The unique identifier for the mutex lock\n * @param fn - The function to execute with exclusive access\n * @param timeout - Optional timeout in milliseconds for lock acquisition\n * @param signal - Optional AbortSignal for cancelling the lock acquisition\n * @returns Promise resolving to the result of the function execution\n * @throws Error if lock acquisition fails or function execution fails\n */\n public async withLock<T>(\n key: string,\n fn: () => Promise<T> | T,\n timeout?: number,\n signal?: AbortSignal,\n ): Promise<T> {\n const acquired = await this.acquire(key, timeout, signal);\n if (!acquired) {\n throw new Error(`Failed to acquire lock for key: ${key}`);\n }\n\n try {\n return await fn();\n } finally {\n await this.release(key);\n }\n }\n\n /**\n * Gets the current configuration of the mutex\n * @returns Object containing the current timeout value\n */\n public getConfig(): Omit<MutexOptions, 'storage'> {\n return {\n timeout: this.defaultTimeout,\n };\n }\n}\n\n/**\n * Default mutex instance for global use\n */\nexport const defaultMutex = new Mutex();\n\n/**\n * Convenience function to execute a function with exclusive access using the default mutex.\n *\n * @param key - The unique identifier for the mutex lock\n * @param fn - The function to execute with exclusive access\n * @param timeout - Optional timeout in milliseconds for lock acquisition\n * @param signal - Optional AbortSignal for cancelling the lock acquisition\n * @returns Promise resolving to the result of the function execution\n *\n * @example\n * ```typescript\n * const controller = new AbortController();\n * const result = await withMutex('shared-resource', async () => {\n * // This code runs with exclusive access\n * return await updateSharedResource();\n * }, 30000, controller.signal);\n * controller.abort(); // Cancels the lock acquisition\n * ```\n */\nexport async function withMutex<T>(\n key: string,\n fn: () => Promise<T> | T,\n timeout?: number,\n signal?: AbortSignal,\n): Promise<T> {\n return defaultMutex.withLock(key, fn, timeout, signal);\n}\n\n/**\n * Creates a new mutex instance with the specified configuration\n * @param options - Configuration options for the mutex\n * @returns New Mutex instance\n *\n * @example\n * ```typescript\n * const mutex = createMutex({\n * timeout: 60000,\n * storage: new RedisMutexStorage()\n * });\n * ```\n */\nexport function createMutex(options: MutexOptions): Mutex {\n return new Mutex(options);\n}\n\n/**\n * Acquires a lock using the default mutex\n * @param key - The unique identifier for the mutex lock\n * @param timeout - Optional timeout in milliseconds for lock acquisition\n * @param signal - Optional AbortSignal for cancelling the acquisition\n * @returns Promise resolving to true if lock was acquired, false if timeout\n */\nexport async function acquireLock(\n key: string,\n timeout?: number,\n signal?: AbortSignal,\n): Promise<boolean> {\n return defaultMutex.acquire(key, timeout, signal);\n}\n\n/**\n * Releases a lock using the default mutex\n * @param key - The unique identifier for the mutex lock\n * @returns Promise that resolves when the lock is released\n */\nexport async function releaseLock(key: string): Promise<void> {\n return defaultMutex.release(key);\n}\n\n/**\n * Checks if a lock is held using the default mutex\n * @param key - The unique identifier for the mutex lock\n * @returns Promise resolving to true if the lock is held, false otherwise\n */\nexport async function isLocked(key: string): Promise<boolean> {\n return defaultMutex.isLocked(key);\n}\n"],"mappings":";;;;;;AAoDA,IAAa,qBAAb,MAAwD;CACtD,AAAiB,wBAAQ,IAAI,IAG3B;;;;;;;;CASF,MAAM,QACJ,KACA,UAAkB,KAClB,QACkB;EAClB,MAAM,SAAS,KAAK,iBAAiB;EACrC,MAAM,YAAY,KAAK,IAAI;EAE3B,OAAO,KAAK,IAAI,IAAI,YAAY,SAAS;GAEvC,oDAAI,OAAQ,SACV,MAAM,IAAI,MAAM,8BAA8B;GAGhD,IAAI,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;IACxB,KAAK,MAAM,IAAI,KAAK;KAAE;KAAQ,YAAY,KAAK,IAAI;IAAE,CAAC;IACtD,OAAO;GACT;GACA,MAAM,KAAK,MAAM,EAAE;EACrB;EAEA,OAAO;CACT;;;;;;CAOA,MAAM,QAAQ,KAA4B;EACxC,KAAK,MAAM,OAAO,GAAG;CACvB;;;;;;CAOA,MAAM,SAAS,KAA+B;EAC5C,OAAO,KAAK,MAAM,IAAI,GAAG;CAC3B;CAEA,AAAQ,mBAA2B;EACjC,OAAO,UAAU,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC;CACvE;CAEA,AAAQ,MAAM,IAA2B;EACvC,OAAO,IAAI,SAAS,YAAY,WAAW,SAAS,EAAE,CAAC;CACzD;AACF;;;;;AAMA,IAAa,QAAb,MAAmB;CACjB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AS,KAA+B;CAC5D,OAAO,aAAa,SAAS,GAAG;AAClC"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/useful-stuff/ratelimiter.ts
4
3
  /**
5
4
  * Default timeout interval for rate limiting in milliseconds
@@ -1 +1 @@
1
- {"version":3,"file":"ratelimiter.js","names":[],"sources":[],"mappings":""}
1
+ {"version":3,"file":"ratelimiter.js","names":[],"sources":["../../../src/utils/useful-stuff/ratelimiter.ts"],"sourcesContent":["/**\n * Default timeout interval for rate limiting in milliseconds\n */\nexport const DEFAULT_TIMEOUT = 60000;\n\n/**\n * Default maximum number of requests allowed per interval\n */\nexport const DEFAULT_MAX_REQUESTS = 10;\n\n/**\n * Interface for rate limit storage implementations.\n * Provides methods to store, retrieve, and delete rate limit data.\n */\nexport interface RateLimitStorage {\n /**\n * Retrieves the current request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the current request count\n */\n get(key: string): Promise<number>;\n\n /**\n * Sets the request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @param value - The request count to store\n * @returns Promise that resolves when the value is stored\n */\n set(key: string, value: number): Promise<void>;\n\n /**\n * Deletes the rate limit entry for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the entry is deleted\n */\n delete(key: string): Promise<void>;\n}\n\n/**\n * Configuration options for rate limiting\n */\nexport interface RateLimitOptions {\n /** Maximum number of requests allowed per interval. Default: 10 */\n maxRequests?: number;\n /** Time interval in milliseconds for the rate limit window. Default: 60000 */\n interval?: number;\n /** Storage implementation for persisting rate limit data. Default: {@link MemoryRateLimitStorage} */\n storage?: RateLimitStorage;\n}\n\n/**\n * In-memory storage implementation for rate limiting.\n * Suitable for single-instance applications.\n */\nexport class MemoryRateLimitStorage implements RateLimitStorage {\n private readonly store = new Map<string, number>();\n\n /**\n * Retrieves the current request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the current request count or 0 if not found\n */\n async get(key: string): Promise<number> {\n return this.store.get(key) || 0;\n }\n\n /**\n * Sets the request count for a given key\n * @param key - The unique identifier for the rate limit entry\n * @param value - The request count to store\n * @returns Promise that resolves immediately\n */\n async set(key: string, value: number): Promise<void> {\n this.store.set(key, value);\n }\n\n /**\n * Deletes the rate limit entry for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves immediately\n */\n async delete(key: string): Promise<void> {\n this.store.delete(key);\n }\n}\n\n/**\n * Rate limiter implementation that enforces request limits per key.\n * Supports configurable request limits and time intervals.\n */\nexport class RateLimiter {\n private readonly limits: Map<string, number> = new Map();\n private readonly lastReset: Map<string, number> = new Map();\n private readonly resetInterval: number;\n\n /**\n * Creates a new rate limiter instance\n * @param maxRequests - Maximum number of requests allowed per interval (default: 10)\n * @param interval - Time interval in milliseconds for the rate limit window (default: 60000)\n * @param storage - Optional storage implementation (default: MemoryRateLimitStorage)\n */\n public constructor(\n private readonly maxRequests: number = DEFAULT_MAX_REQUESTS,\n private readonly interval: number = DEFAULT_TIMEOUT,\n private storage: RateLimitStorage = new MemoryRateLimitStorage(),\n ) {\n this.resetInterval = interval;\n }\n\n /**\n * Sets the storage implementation for the rate limiter\n * @param storage - The storage implementation to use\n */\n public setStorage(storage: RateLimitStorage) {\n this.storage = storage;\n }\n\n /**\n * Gets the storage implementation for the rate limiter\n * @returns The storage implementation\n */\n public getStorage(): RateLimitStorage {\n return this.storage;\n }\n\n /**\n * Checks if a request is allowed for the given key and increments the counter if allowed\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to true if the request is allowed, false if rate limited\n */\n public async limit(key: string): Promise<boolean> {\n const now = Date.now();\n const lastReset = this.lastReset.get(key) || 0;\n const timeSinceReset = now - lastReset;\n\n // Reset counter if interval has passed\n if (timeSinceReset > this.resetInterval) {\n await this.storage.delete(key);\n this.lastReset.set(key, now);\n this.limits.set(key, 0);\n }\n\n // Get current count from storage\n const currentCount = await this.storage.get(key);\n\n // Check if limit exceeded\n if (currentCount >= this.maxRequests) {\n return false;\n }\n\n // Increment counter\n const newCount = currentCount + 1;\n await this.storage.set(key, newCount);\n this.limits.set(key, newCount);\n\n return true;\n }\n\n /**\n * Gets the remaining requests allowed for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the number of remaining requests\n */\n public async getRemaining(key: string): Promise<number> {\n const currentCount = await this.storage.get(key);\n return Math.max(0, this.maxRequests - currentCount);\n }\n\n /**\n * Gets the time until the rate limit resets for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the time in milliseconds until reset, or 0 if no limit is active\n */\n public async getResetTime(key: string): Promise<number> {\n const lastReset = this.lastReset.get(key) || 0;\n const now = Date.now();\n const timeSinceReset = now - lastReset;\n\n if (timeSinceReset >= this.resetInterval) {\n return 0;\n }\n\n return this.resetInterval - timeSinceReset;\n }\n\n /**\n * Resets the rate limit for a given key\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the reset is complete\n */\n public async reset(key: string): Promise<void> {\n await this.storage.delete(key);\n this.limits.delete(key);\n this.lastReset.delete(key);\n }\n\n /**\n * Gets the current configuration of the rate limiter\n * @returns Object containing the current maxRequests and interval values\n */\n public getConfig(): Omit<RateLimitOptions, 'storage'> {\n return {\n maxRequests: this.maxRequests,\n interval: this.interval,\n };\n }\n}\n\n/**\n * Default rate limiter instance for global use\n */\nexport const defaultRateLimiter = new RateLimiter();\n\n/**\n * Convenience function to check if a request is allowed for a given key.\n * Uses the default rate limiter instance.\n *\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to true if the request is allowed, false if rate limited\n *\n * @example\n * ```typescript\n * const allowed = await ratelimit('user:123');\n * // update the default rate limiter config\n * import { defaultRateLimiter } from 'commandkit/ratelimit';\n *\n * // update max allowed requests\n * defaultRateLimiter.setMaxRequests(10);\n *\n * // update the timeout interval\n * defaultRateLimiter.setInterval(30000);\n *\n * // update the storage implementation\n * defaultRateLimiter.setStorage(new RedisStorage());\n * ```\n */\nexport async function ratelimit(key: string): Promise<boolean> {\n return defaultRateLimiter.limit(key);\n}\n\n/**\n * Creates a new rate limiter instance with the specified configuration\n * @param options - Configuration options for the rate limiter\n * @returns New RateLimiter instance\n *\n * @example\n * ```typescript\n * const limiter = createRateLimiter({\n * maxRequests: 5,\n * interval: 30000,\n * storage: new CustomStorage()\n * });\n * ```\n */\nexport function createRateLimiter(options: RateLimitOptions): RateLimiter {\n return new RateLimiter(\n options.maxRequests,\n options.interval,\n options.storage,\n );\n}\n\n/**\n * Gets the remaining requests for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the number of remaining requests\n */\nexport async function getRemainingRequests(key: string): Promise<number> {\n return defaultRateLimiter.getRemaining(key);\n}\n\n/**\n * Gets the reset time for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise resolving to the time in milliseconds until reset\n */\nexport async function getResetTime(key: string): Promise<number> {\n return defaultRateLimiter.getResetTime(key);\n}\n\n/**\n * Resets the rate limit for a key using the default rate limiter\n * @param key - The unique identifier for the rate limit entry\n * @returns Promise that resolves when the reset is complete\n */\nexport async function resetRateLimit(key: string): Promise<void> {\n return defaultRateLimiter.reset(key);\n}\n"],"mappings":";;;;;AAGA,MAAa,kBAAkB;;;;AAK/B,MAAa,uBAAuB;;;;;AA8CpC,IAAa,yBAAb,MAAgE;CAC9D,AAAiB,wBAAQ,IAAI,IAAoB;;;;;;CAOjD,MAAM,IAAI,KAA8B;EACtC,OAAO,KAAK,MAAM,IAAI,GAAG,KAAK;CAChC;;;;;;;CAQA,MAAM,IAAI,KAAa,OAA8B;EACnD,KAAK,MAAM,IAAI,KAAK,KAAK;CAC3B;;;;;;CAOA,MAAM,OAAO,KAA4B;EACvC,KAAK,MAAM,OAAO,GAAG;CACvB;AACF;;;;;AAMA,IAAa,cAAb,MAAyB;CAYJ;CACA;CACT;CAbV,AAAiB,yBAA8B,IAAI,IAAI;CACvD,AAAiB,4BAAiC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ACL,aAAa,KAAK;GAClB,UAAU,KAAK;EACjB;CACF;AACF;;;;AAKA,MAAa,qBAAqB,IAAI,YAAY;;;;;;;;;;;;;;;;;;;;;;;;AAyBlD,eAAsB,UAAU,KAA+B;CAC7D,OAAO,mBAAmB,MAAM,GAAG;AACrC;;;;;;;;;;;;;;;AAgBA,SAAgB,kBAAkB,SAAwC;CACxE,OAAO,IAAI,YACT,QAAQ,aACR,QAAQ,UACR,QAAQ,OACV;AACF;;;;;;AAOA,eAAsB,qBAAqB,KAA8B;CACvE,OAAO,mBAAmB,aAAa,GAAG;AAC5C;;;;;;AAOA,eAAsB,aAAa,KAA8B;CAC/D,OAAO,mBAAmB,aAAa,GAAG;AAC5C;;;;;;AAOA,eAAsB,eAAe,KAA4B;CAC/D,OAAO,mBAAmB,MAAM,GAAG;AACrC"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/utils/useful-stuff/semaphore.ts
4
3
  /**
5
4
  * In-memory storage implementation for semaphore permits.