{"version":3,"file":"index.cjs","names":["clientGenerator","groupedClientGenerator","operationsGenerator","pluginOasName","pluginZodName","path","options","groupName: Group['name']","baseURL","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.tsx'\nimport { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = definePlugin<PluginClient>((options) => {\n  const bundle = options.bundle ?? false\n  const {\n    output = { path: 'clients', barrelType: 'named' },\n    group,\n    urlType = false,\n    exclude = [],\n    include,\n    override = [],\n    transformers = {},\n    dataReturnType = 'data',\n    paramsType = 'inline',\n    pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n    operations = false,\n    baseURL,\n    paramsCasing,\n    generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),\n    parser = 'client',\n    client = 'axios',\n    importPath,\n    contentType,\n  } = options\n\n  const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)\n\n  return {\n    name: pluginClientName,\n    options: {\n      client,\n      bundle,\n      output,\n      group,\n      parser,\n      dataReturnType,\n      importPath: resolvedImportPath,\n      paramsType,\n      paramsCasing,\n      pathParamsType,\n      baseURL,\n      urlType,\n    },\n    pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n    resolvePath(baseName, pathMode, options) {\n      const root = path.resolve(this.config.root, this.config.output.path)\n      const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n      if (mode === 'single') {\n        /**\n         * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n         * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n         */\n        return path.resolve(root, output.path)\n      }\n\n      if (group && (options?.group?.path || options?.group?.tag)) {\n        const groupName: Group['name'] = group?.name\n          ? group.name\n          : (ctx) => {\n              if (group?.type === 'path') {\n                return `${ctx.group.split('/')[1]}`\n              }\n              return `${camelCase(ctx.group)}Controller`\n            }\n\n        return path.resolve(\n          root,\n          output.path,\n          groupName({\n            group: group.type === 'path' ? options.group.path! : options.group.tag!,\n          }),\n          baseName,\n        )\n      }\n\n      return path.resolve(root, output.path, baseName)\n    },\n    resolveName(name, type) {\n      const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n      if (type) {\n        return transformers?.name?.(resolvedName, type) || resolvedName\n      }\n\n      return resolvedName\n    },\n    async install() {\n      const root = path.resolve(this.config.root, this.config.output.path)\n      const mode = getMode(path.resolve(root, output.path))\n      const oas = await this.getOas()\n      const baseURL = await this.getBaseURL()\n\n      // pre add bundled fetch\n      const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')\n\n      if (bundle && !this.plugin.options.importPath && !containsFetch) {\n        await this.addFile({\n          baseName: 'fetch.ts',\n          path: path.resolve(root, '.kubb/fetch.ts'),\n          sources: [\n            {\n              name: 'fetch',\n              value: resolveModuleSource(\n                this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n              ).source,\n              isExportable: true,\n              isIndexable: true,\n            },\n          ],\n        })\n      }\n\n      const operationGenerator = new OperationGenerator(\n        baseURL\n          ? {\n              ...this.plugin.options,\n              baseURL,\n            }\n          : this.plugin.options,\n        {\n          fabric: this.fabric,\n          oas,\n          pluginManager: this.pluginManager,\n          plugin: this.plugin,\n          contentType,\n          exclude,\n          include,\n          override,\n          mode,\n        },\n      )\n\n      const files = await operationGenerator.build(...generators)\n\n      await this.addFile(...files)\n\n      const barrelFiles = await getBarrelFiles(this.fabric.files, {\n        type: output.barrelType ?? 'named',\n        root,\n        output,\n        meta: {\n          pluginKey: this.plugin.key,\n        },\n        logger: this.logger,\n      })\n\n      await this.addFile(...barrelFiles)\n    },\n  }\n})\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,mBAAmB;AAEhC,MAAa,8CAA2C,YAAY;CAClE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,EACJ,SAAS;EAAE,MAAM;EAAW,YAAY;EAAS,EACjD,OACA,UAAU,OACV,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,iBAAiB,QACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa,OACb,SACA,cACA,aAAa;EAACA;EAAiB,QAAQC,4CAAyB;EAAW,aAAaC,yCAAsB;EAAU,CAAC,OAAO,QAAQ,EACxI,SAAS,UACT,SAAS,SACT,YACA,gBACE;AAIJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA,YAXuB,eAAe,CAAC,SAAS,+BAA+B,WAAW;GAY1F;GACA;GACA;GACA;GACA;GACD;EACD,KAAK,CAACC,iCAAe,WAAW,QAAQC,kCAAgB,OAAU,CAAC,OAAO,QAAQ;EAClF,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,2CAAa,IAAI,MAAM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