{"version":3,"file":"batch.mjs","sources":["../../../../../src/core/actions/v3/batch.ts"],"sourcesContent":["import type {\n  BatchResultByIndex,\n  BatchResultByIndexDetailed,\n  BatchResultByName,\n  BatchResultByNameDetailed,\n  CallBatchResult,\n  IB24BatchOptions\n} from '../../../types/b24'\nimport type {\n  BatchCommandsArrayUniversal,\n  BatchCommandsObjectUniversal,\n  BatchNamedCommandsUniversal\n} from '../../../types/http'\nimport { AbstractBatch } from '../abstract-batch'\nimport { ApiVersion } from '../../../types/b24'\n\nexport type ActionBatchV3 = {\n  calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal | BatchNamedCommandsUniversal\n  options?: IB24BatchOptions\n}\n\n/**\n * Executes a batch request to the Bitrix24 REST API with a maximum number of commands of no more than 50. `restApi:v3`\n * Allows you to execute multiple requests in a single API call, significantly improving performance.\n *\n * Sends up to 50 commands in a single v3 batch HTTP call and returns their results together.\n * That 50 is the **SDK's** ceiling on v3, not the portal's — 51 commands posted straight at\n * the endpoint answered HTTP 200 with 51 results; see {@link MAX_BATCH_COMMANDS_V3}.\n * Supports array, object, and named-command formats. Unlike `BatchByChunkV3`, it does not split\n * large command sets automatically — callers must keep the command count within the 50-command\n * limit. Compared to `BatchV2`, it routes through the v3 endpoint without a client-side method\n * allowlist.\n */\nexport class BatchV3 extends AbstractBatch {\n  /**\n   * Executes a batch request to the Bitrix24 REST API: up to 50 commands in one\n   * HTTP call, in array, object or named-command form. `restApi:v3`\n   *\n   * **The argument reference, the three `calls` formats, the options table and\n   * worked examples live on the [batch page](https://bitrix24.github.io/b24jssdk/docs/working-with-the-rest-api/batch-rest-api-ver3/).**\n   * Deliberately not repeated here: that copy is compiled on every CI run and\n   * this one would not be — no pass type-checks a JSDoc `@example` (#420).\n   *\n   * What matters while editing this file:\n   *   - **50 commands maximum**, and on v3 that number is the SDK's own rather\n   *     than the portal's — see {@link MAX_BATCH_COMMANDS_V3} for what was\n   *     measured. This action does not split; `BatchByChunkV3` is the one that\n   *     does.\n   *   - **`getData()` has no `result` envelope here.** It returns the keyed map\n   *     or array directly — only `call.make` returns `{ result, time }` (#425).\n   *   - **Flags live in `options`.** At the top level they are dropped, which is\n   *     why `_warnMisplacedOptions` runs first (#426).\n   *   - **v3 batch is all-or-nothing.** Per-command errors do not surface; one\n   *     failing command fails the envelope.\n   *\n   * @template T - The data type returned by batch query commands (default `unknown`)\n   * @param {ActionBatchV3} options - `calls` plus an optional `options` bag; see\n   *   {@link ActionBatchV3} and {@link IB24BatchOptions} for the members.\n   * @returns {Promise<CallBatchResult<T>>} results in the shape of the input:\n   *   an array for array input, an object keyed by command name for named input.\n   *   With `options.returnAjaxResult` each entry is an `AjaxResult` rather than\n   *   the raw payload.\n   *\n   * @example\n   * import type { AjaxResult } from '@bitrix24/b24jssdk'\n   *\n   * interface Task { id: number, title: string }\n   * const response = await b24.actions.v3.batch.make<{ item: Task }>({\n   *   calls: {\n   *     first: ['tasks.task.get', { taskId: 1 }],\n   *     second: ['tasks.task.get', { taskId: 2 }]\n   *   },\n   *   options: { isHaltOnError: false, returnAjaxResult: true, requestId: 'batch-123' }\n   * })\n   * if (!response.isSuccess) {\n   *   throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n   * }\n   * const data = response.getData()! as Record<string, AjaxResult<{ item: Task }>>\n   * console.log(data['first']!.getData()!.result.item)\n   *\n   * @warning The maximum number of commands in one batch request is 50.\n   * @note A batch request executes faster than sequential single calls,\n   *     but if one command fails, the entire batch may fail\n   *     (depending on API settings and options).\n   */\n  /**\n   * Overloads, not decoration. The shape of a batch answer is decided by the\n   * arguments — a named record of commands answers by name, an array answers by\n   * index, and `returnAjaxResult` decides whether each entry is the payload or\n   * the `AjaxResult` wrapping it. None of that is visible on the returned value,\n   * so without these a caller has the union and no way to narrow it, and has to\n   * cast at exactly the point the types are worth having (#518).\n   *\n   * `T` is **one command's payload** in every overload.\n   *\n   * The last signature keeps a dynamic `returnAjaxResult` working: when the flag\n   * is a `boolean` the compiler cannot read as a literal, the union is still the\n   * honest answer.\n   */\n  public async make<T = unknown>(options: {\n    calls: BatchNamedCommandsUniversal\n    options: IB24BatchOptions & { returnAjaxResult: true }\n  }): Promise<BatchResultByNameDetailed<T>>\n\n  public async make<T = unknown>(options: {\n    calls: BatchNamedCommandsUniversal\n    options?: IB24BatchOptions & { returnAjaxResult?: false }\n  }): Promise<BatchResultByName<T>>\n\n  public async make<T = unknown>(options: {\n    calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal\n    options: IB24BatchOptions & { returnAjaxResult: true }\n  }): Promise<BatchResultByIndexDetailed<T>>\n\n  public async make<T = unknown>(options: {\n    calls: BatchCommandsArrayUniversal | BatchCommandsObjectUniversal\n    options?: IB24BatchOptions & { returnAjaxResult?: false }\n  }): Promise<BatchResultByIndex<T>>\n\n  public async make<T = unknown>(options: ActionBatchV3): Promise<CallBatchResult<T>>\n\n  public async make<T = unknown>(options: ActionBatchV3): Promise<CallBatchResult<T>> {\n    this._warnMisplacedOptions(\n      options,\n      ['isHaltOnError', 'returnAjaxResult', 'requestId'],\n      'options'\n    )\n\n    const opts = {\n      ...options.options,\n      apiVersion: ApiVersion.v3\n    }\n\n    // No client-side allowlist: every command is sent to the v3 batch endpoint\n    // and the server validates each method (unknown ones come back as errors).\n    const response = await this._b24.getHttpClient(ApiVersion.v3).batch<T>(options.calls, opts)\n\n    return this._processBatchResponse<T>(response, options.calls, opts)\n  }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAiCO,MAAM,gBAAgB,aAAA,CAAc;AAAA,EAjC3C;AAiC2C,IAAA,MAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAAA;AAAA,EAwFzC,MAAa,KAAkB,OAAA,EAAqD;AAClF,IAAA,IAAA,CAAK,qBAAA;AAAA,MACH,OAAA;AAAA,MACA,CAAC,eAAA,EAAiB,kBAAA,EAAoB,WAAW,CAAA;AAAA,MACjD;AAAA,KACF;AAEA,IAAA,MAAM,IAAA,GAAO;AAAA,MACX,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,YAAY,UAAA,CAAW;AAAA,KACzB;AAIA,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,aAAA,CAAc,UAAA,CAAW,EAAE,CAAA,CAAE,KAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,IAAI,CAAA;AAE1F,IAAA,OAAO,IAAA,CAAK,qBAAA,CAAyB,QAAA,EAAU,OAAA,CAAQ,OAAO,IAAI,CAAA;AAAA,EACpE;AACF;;;;"}