{"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 = 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;AAC/F,KAAI,WAAW,MACb,QAAO,EAAE,UAAS,OAAM,IAAI,EAAE;CAIhC,MAAM,EAAE,mBAAmB,mBADa,OAAO,WAAW,WAAW,EAAE,mBAAmB,QAAQ,GAAG;CAErG,MAAM,MAAM,qBAAqB,kBAAkB;CACnD,MAAM,WAAWA,gCAAe,KAAK,IAAI,KAAK,eAAe,CAAC;AAE9D,QAAO,EACL,UAAS,OAAM,SAAS,QAAQ,GAAG,EACpC"}