{"version":3,"file":"HttpMigration.mjs","sources":["../src/HttpMigration.ts"],"sourcesContent":["import { OpenApi } from \"./OpenApi\";\nimport { OpenApiV3 } from \"./OpenApiV3\";\nimport { OpenApiV3_1 } from \"./OpenApiV3_1\";\nimport { SwaggerV2 } from \"./SwaggerV2\";\nimport { HttpMigrateApplicationComposer } from \"./composers/HttpMigrateApplicationComposer\";\nimport { HttpMigrateRouteFetcher } from \"./http/HttpMigrateRouteFetcher\";\nimport { IHttpConnection } from \"./structures/IHttpConnection\";\nimport { IHttpMigrateApplication } from \"./structures/IHttpMigrateApplication\";\nimport { IHttpMigrateRoute } from \"./structures/IHttpMigrateRoute\";\nimport { IHttpResponse } from \"./structures/IHttpResponse\";\n\n/**\n * HTTP migration application composer from OpenAPI document.\n *\n * `HttpMigration` is a module for composing HTTP migration application from the\n * {@link OpenApi.IDocument OpenAPI document}. It is designed for helping the\n * OpenAPI generator libraries, which converts\n * {@link OpenApi.IOperation OpenAPI operations} to an RPC (Remote Procedure\n * Call) function.\n *\n * The key feature of the `HttpModule` is the {@link HttpMigration.application}\n * function. It converts the {@link OpenApi.IOperation OpenAPI operations} to the\n * {@link IHttpMigrateRoute HTTP migration route}, and it normalizes the OpenAPI\n * operations to the RPC function calling suitable route structure.\n *\n * The other functions, {@link HttpMigration.execute} and\n * {@link HttpMigration.propagate}, are for executing the HTTP request to the\n * HTTP server. The {@link HttpMigration.execute} function returns the response\n * body from the API endpoint when the status code is `200` or `201`. Otherwise,\n * it throws an {@link HttpError} when the status code is not `200` or `201`. The\n * {@link HttpMigration.propagate} function returns the response information from\n * the API endpoint, including the status code, headers, and response body.\n *\n * The {@link HttpLlm} module is a good example utilizing this `HttpMigration`\n * module for composing RPC function calling application. The {@link HttpLlm}\n * module composes LLM (Large Language Model) function calling application from\n * the OpenAPI document bypassing through the {@link IHttpLlmApplication} type.\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport namespace HttpMigration {\n  /* -----------------------------------------------------------\n    COMPOSER\n  ----------------------------------------------------------- */\n  /**\n   * Convert HTTP migration application from OpenAPI document.\n   *\n   * `HttpMigration.application()` is a function converting the\n   * {@link OpenApi.IDocument OpenAPI document} and its\n   * {@link OpenApi.IOperation operations} to the\n   * {@link IHttpMigrateApplication HTTP migration application}.\n   *\n   * The HTTP migration application is designed for helping the OpenAPI\n   * generator libraries, which converts OpenAPI operations to an RPC (Remote\n   * Procedure Call) function. To support the OpenAPI generator libraries,\n   * {@link IHttpMigrateRoute} takes below normalization rules:\n   *\n   * - Path parameters are separated to atomic level.\n   * - Query parameters are binded into one object.\n   * - Header parameters are binded into one object.\n   * - Allow only below HTTP methods\n   *\n   *   - `head`\n   *   - `get`\n   *   - `post`\n   *   - `put`\n   *   - `patch`\n   *   - `delete`\n   * - Allow only below content media types\n   *\n   *   - `application/json`\n   *   - `application/x-www-form-urlencoded`\n   *   - `multipart/form-data`\n   *   - `text/plain`\n   *\n   * If there're some {@link OpenApi.IOperation API operations} which canont\n   * adjust the above rules or there're some logically insensible, these\n   * operation would be failed to migrate and registered into the\n   * {@link IHttpMigrateApplication.errors}.\n   *\n   * @param document OpenAPI document to migrate.\n   * @returns Migrated application.\n   */\n  export const application = (\n    document:\n      | OpenApi.IDocument\n      | SwaggerV2.IDocument\n      | OpenApiV3.IDocument\n      | OpenApiV3_1.IDocument,\n  ): IHttpMigrateApplication =>\n    HttpMigrateApplicationComposer.compose(OpenApi.convert(document));\n\n  /** Properties for the request to the HTTP server. */\n  export interface IFetchProps {\n    /** Connection info to the HTTP server. */\n    connection: IHttpConnection;\n\n    /** Route information for the migration. */\n    route: IHttpMigrateRoute;\n\n    /**\n     * Path parameters.\n     *\n     * Path parameters with sequenced array or key-value paired object.\n     */\n    parameters:\n      | Array<string | number | boolean | bigint | null>\n      | Record<string, string | number | boolean | bigint | null>;\n\n    /** Query parameters as a key-value paired object. */\n    query?: object | undefined;\n\n    /** Request body data. */\n    body?: object | undefined;\n  }\n\n  /* -----------------------------------------------------------\n    FETCHERS\n  ----------------------------------------------------------- */\n  /**\n   * Execute the HTTP request.\n   *\n   * `HttpMigration.execute()` is a function executing the HTTP request to the\n   * HTTP server.\n   *\n   * It returns the response body from the API endpoint when the status code is\n   * `200` or `201`. Otherwise, it throws an {@link HttpError} when the status\n   * code is not `200` or `201`.\n   *\n   * If you want to get more information than the response body, or get the\n   * detailed response information even when the status code is `200` or `201`,\n   * use the {@link HttpMigration.propagate} function instead.\n   *\n   * @param props Properties for the request.\n   * @returns Return value (response body) from the API endpoint.\n   * @throws HttpError when the API endpoint responds none 200/201 status.\n   */\n  export const execute = (props: IFetchProps): Promise<unknown> =>\n    HttpMigrateRouteFetcher.execute(props);\n\n  /**\n   * Propagate the HTTP request.\n   *\n   * `HttpMigration.propagate()` is a function propagating the request to the\n   * HTTP server.\n   *\n   * It returns the response information from the API endpoint, including the\n   * status code, headers, and response body.\n   *\n   * Even if the status code is not `200` or `201`, this function would return\n   * the response information. By the way, if the connection to the HTTP server\n   * is failed, this function would throw an {@link Error}.\n   *\n   * @param props Properties for the request.\n   * @returns Response from the API endpoint.\n   * @throws Error when the connection is failed.\n   */\n  export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>\n    HttpMigrateRouteFetcher.propagate(props);\n}\n"],"names":["HttpMigration","application","document","HttpMigrateApplicationComposer","compose","OpenApi","convert","execute","props","HttpMigrateRouteFetcher","propagate"],"mappings":";;;;;;AAwCM,IAAWA;;CAAjB,SAAiBA;IA2CFA,cAAAC,cACXC,YAMAC,+BAA+BC,QAAQC,QAAQC,QAAQJ;IA+C5CF,cAAAO,UAAWC,SACtBC,wBAAwBF,QAAQC;IAmBrBR,cAAAU,YAAaF,SACxBC,wBAAwBC,UAAUF;AACrC,EAvHD,CAAiBR,kBAAAA,gBAAa,CAAA;;"}