{"version":3,"file":"rate-limit.cjs","names":["createThrottle"],"sources":["../../src/utils/rate-limit.ts"],"sourcesContent":["import { createThrottle } from \"./throttle\";\n\nconst DEFAULT_REQUESTS_PER_SECOND = 6;\nconst MAX_RATE_LIMIT = 1_000;\n\nexport interface RateLimitConfig {\n  /**\n   * Maximum number of MAPI requests to start per second.\n   * Defaults to 6. Capped at 1000.\n   */\n  requestsPerSecond?: number;\n  /**\n   * @deprecated Use `requestsPerSecond` instead.\n   * @todo(next-major): Remove this field.\n   */\n  maxConcurrency?: number;\n}\n\nexport interface ThrottleManager {\n  execute: <T>(fn: () => Promise<T>) => Promise<T>;\n}\n\n/**\n * Creates a `ThrottleManager` from the user-supplied `rateLimit` config.\n *\n * - `false`                       -> no throttling (passthrough)\n * - `number`                      -> N requests per second\n * - `{ requestsPerSecond: n }`    -> N requests per second\n * - `{}` / `undefined` (default)  -> DEFAULT_REQUESTS_PER_SECOND per second\n */\nexport function createThrottleManager(config: RateLimitConfig | number | false): ThrottleManager {\n  if (config === false) {\n    return { execute: (fn) => fn() };\n  }\n\n  const resolvedConfig: RateLimitConfig =\n    typeof config === \"number\" ? { requestsPerSecond: config } : config;\n  const { requestsPerSecond, maxConcurrency } = resolvedConfig;\n  const rps = requestsPerSecond ?? maxConcurrency ?? DEFAULT_REQUESTS_PER_SECOND;\n  const throttle = createThrottle(Math.min(rps, MAX_RATE_LIMIT));\n\n  return {\n    execute: (fn) => throttle.execute(fn),\n  };\n}\n"],"mappings":";;AAEA,MAAM,8BAA8B;AACpC,MAAM,iBAAiB;;;;;;;;;AA2BvB,SAAgB,sBAAsB,QAA2D;CAC/F,IAAI,WAAW,OACb,OAAO,EAAE,UAAU,OAAO,GAAG,EAAE;CAKjC,MAAM,EAAE,mBAAmB,mBADzB,OAAO,WAAW,WAAW,EAAE,mBAAmB,OAAO,IAAI;CAG/D,MAAM,WAAWA,iBAAAA,eAAe,KAAK,IADzB,qBAAqB,kBAAkB,6BACL,cAAc,CAAC;CAE7D,OAAO,EACL,UAAU,OAAO,SAAS,QAAQ,EAAE,EACtC;AACF"}