{"version":3,"sources":["../../../src/scripts/CreateHttpClient/httpClientTemplate.ts","../../../src/config/index.ts"],"sourcesContent":["import {configStore} from '../../config/index.ts';\n\nexport function httpClientTemplate() {\n  if (configStore?.hook === 'NG') {\n    return `\n    /* eslint-disable */\n    /* tslint:disable */\n    import {  HttpHeaders, HttpRequest, HttpClient as NgHttpClient } from \"@angular/common/http\";\n    import { Injectable,Inject } from \"@angular/core\";\n\n    type IMethod = 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS'\n\n    @Injectable()\n    export class HttpClient {\n      constructor(\n        private http: NgHttpClient,\n        @Inject(String) public baseUrl: string,\n      ) {\n      }\n      public request = <R, Q>(\n        data: Omit<\n          HttpRequest<Q|undefined>,\n          | 'context'\n          | 'reportProgress'\n          | 'urlWithParams'\n          | 'serializeBody'\n          | 'detectContentTypeHeader'\n          | 'clone'\n          | 'withCredentials'\n        >,\n      ) => {\n\n        return this.http.request<R>(data.method.toUpperCase() as IMethod, this.baseUrl + data.url,{\n          body: data.body ? data.body:null,\n          params:data.params,\n          headers:data.headers\n        });\n      };\n    }\n`;\n  } else\n    return `/* eslint-disable */\n/* tslint:disable */\nimport type { AxiosInstance, AxiosRequestConfig, AxiosResponse, HeadersDefaults, ResponseType } from 'axios'\nimport axios from 'axios'\n\nexport type QueryParamsType = Record<string | number, any>\n\nexport interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {\n  /** set parameter to \\`true\\` for call \\`securityWorker\\` for this request */\n  secure?: boolean\n  /** request path */\n  path: string\n  /** content type of request body */\n  type?: ContentType\n  /** query params */\n  query?: QueryParamsType\n  /** format of response (i.e. response.json() -> format: \"json\") */\n  format?: ResponseType\n  /** request body */\n  body?: unknown\n}\n\nexport type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>\nexport const getData = (data: undefined | unknown) => {\n  if (data) {\n    return data;\n  } else {\n    return {};\n  }\n};\nexport interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {\n  securityWorker?: (\n    securityData: SecurityDataType | null,\n  ) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void\n  secure?: boolean\n  format?: ResponseType\n  instance?: AxiosInstance\n}\n\nexport enum ContentType {\n  Json = 'application/json',\n  FormData = 'multipart/form-data',\n  UrlEncoded = 'application/x-www-form-urlencoded',\n  Text = 'text/plain',\n}\nexport type AxiosOpt = Omit<AxiosRequestConfig, \"data\" | \"params\" | \"url\" | \"responseType\">;\nexport class HttpClient<SecurityDataType = unknown> {\n  public instance: AxiosInstance\n  private securityData: SecurityDataType | null = null\n  private securityWorker?: ApiConfig<SecurityDataType>['securityWorker']\n  private secure?: boolean\n  private format?: ResponseType\n\n  constructor({ securityWorker, secure, format,instance, ...axiosConfig }: ApiConfig<SecurityDataType> = {}) {\n    this.instance = instance?instance:axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || '' })\n    this.secure = secure\n    this.format = format\n    this.securityWorker = securityWorker\n  }\n\n  public setSecurityData = (data: SecurityDataType | null) => {\n    this.securityData = data\n  }\n\n  protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig {\n    const method = params1.method || (params2 && params2.method)\n\n    return {\n      ...this.instance.defaults,\n      ...params1,\n      ...(params2 || {}),\n      headers: {\n        ...((method && this.instance.defaults.headers[method.toLowerCase() as keyof HeadersDefaults]) || {}),\n        ...(params1.headers || {}),\n        ...((params2 && params2.headers) || {}),\n      },\n    }\n  }\n\n  protected stringifyFormItem(formItem: unknown) {\n    if (typeof formItem === 'object' && formItem !== null) {\n      return JSON.stringify(formItem)\n    } else {\n        \n      return \\`\\${formItem}\\`\n    }\n  }\n\n  protected createFormData(input: Record<string, unknown>): FormData {\n    return Object.keys(input || {}).reduce((formData, key) => {\n      const property = input[key]\n      const propertyContent: any[] = property instanceof Array ? property : [property]\n\n      for (const formItem of propertyContent) {\n        const isFileType = formItem instanceof Blob || formItem instanceof File\n        formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem))\n      }\n\n      return formData\n    }, new FormData())\n  }\n\n  public request = async <T = any, _E = any>({\n    secure,\n    path,\n    type,\n    query,\n    format,\n    body,\n    ...params\n  }: FullRequestParams): Promise<AxiosResponse<T>> => {\n    const secureParams =\n      ((typeof secure === 'boolean' ? secure : this.secure) &&\n        this.securityWorker &&\n        (await this.securityWorker(this.securityData))) ||\n      {}\n    const requestParams = this.mergeRequestParams(params, secureParams)\n    const responseFormat = format || this.format || undefined\n\n    if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {\n      body = this.createFormData(body as Record<string, unknown>)\n    }\n\n    if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {\n      body = JSON.stringify(body)\n    }\n\n    return this.instance.request({\n      ...requestParams,\n      headers: {\n        ...(requestParams.headers || {}),\n        ...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),\n      },\n      params: query,\n      responseType: responseFormat,\n      data: body,\n      url: path,\n    })\n  }\n}\n\n\n`;\n}\n","import chalk from 'chalk';\nimport ora from 'ora';\nimport {cosmiconfig} from 'cosmiconfig';\nimport {IConfig} from '../types.ts';\nimport {ConfigStore} from './store/store.ts';\nconst spinner = ora('get hookgenrc config file');\nconst explorer = () => cosmiconfig('hookgenrc');\n// eslint-disable-next-line prefer-const\nexport let configStore: ConfigStore | undefined = undefined;\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n//@ts-ignore\nexport async function getConfig(): Promise<IConfig | undefined> {\n  spinner.start();\n  try {\n    const configFile = await explorer().load('./hookgenrc.json');\n    if (configFile?.isEmpty) {\n      spinner.warn();\n      console.warn(chalk.yellow(' └ codegen file is empty!'));\n      return Promise.resolve(undefined);\n    } else {\n      spinner.succeed();\n      configStore = new ConfigStore(configFile?.config as IConfig);\n      return configFile?.config as IConfig;\n    }\n  } catch (error) {\n    spinner.fail();\n    console.error(\n      chalk.bgRedBright(error ? error : ' └ Error get config file')\n    );\n    throw new Error(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