{"version":3,"file":"index.cjs","names":["staticClassClientGenerator","classClientGenerator","clientGenerator","groupedClientGenerator","operationsGenerator","pluginOasName","pluginZodName","path","camelCase","fetchClientSource","axiosClientSource","configSource","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { classClientGenerator, operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.tsx'\nimport { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'\nimport { staticClassClientGenerator } from './generators/staticClassClientGenerator.tsx'\nimport { source as axiosClientSource } from './templates/clients/axios.source.ts'\nimport { source as fetchClientSource } from './templates/clients/fetch.source.ts'\nimport { source as configSource } from './templates/config.source.ts'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = definePlugin<PluginClient>((options) => {\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    clientType = 'function',\n    parser = 'client',\n    client = 'axios',\n    importPath,\n    contentType,\n    bundle = false,\n    wrapper,\n  } = options\n\n  const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)\n\n  const defaultGenerators = [\n    clientType === 'staticClass' ? staticClassClientGenerator : clientType === 'class' ? classClientGenerator : clientGenerator,\n    group && clientType === 'function' ? groupedClientGenerator : undefined,\n    operations ? operationsGenerator : undefined,\n  ].filter((x): x is NonNullable<typeof x> => Boolean(x))\n\n  const generators = options.generators ?? defaultGenerators\n\n  return {\n    name: pluginClientName,\n    options: {\n      client,\n      clientType,\n      bundle,\n      output,\n      group,\n      parser,\n      dataReturnType,\n      importPath: resolvedImportPath,\n      paramsType,\n      paramsCasing,\n      pathParamsType,\n      baseURL,\n      urlType,\n      wrapper,\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      if (bundle && !this.plugin.options.importPath) {\n        await this.addFile({\n          baseName: 'fetch.ts',\n          path: path.resolve(root, '.kubb/fetch.ts'),\n          sources: [\n            {\n              name: 'fetch',\n              value: this.plugin.options.client === 'fetch' ? fetchClientSource : axiosClientSource,\n              isExportable: true,\n              isIndexable: true,\n            },\n          ],\n          imports: [],\n          exports: [],\n        })\n      }\n\n      await this.addFile({\n        baseName: 'config.ts',\n        path: path.resolve(root, '.kubb/config.ts'),\n        sources: [\n          {\n            name: 'config',\n            value: configSource,\n            isExportable: false,\n            isIndexable: false,\n          },\n        ],\n        imports: [],\n        exports: [],\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          events: this.events,\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.upsertFile(...files)\n\n      const barrelFiles = await getBarrelFiles(this.fabric.files, {\n        root,\n        output,\n        meta: {\n          pluginKey: this.plugin.key,\n        },\n      })\n\n      await this.upsertFile(...barrelFiles)\n    },\n  }\n})\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,mBAAmB;AAEhC,MAAa,gBAAA,GAAA,WAAA,eAA2C,YAAY;CAClE,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,YACb,SAAS,UACT,SAAS,SACT,YACA,aACA,SAAS,OACT,YACE;CAEJ,MAAM,qBAAqB,eAAe,CAAC,SAAS,+BAA+B,WAAW,KAAA;CAE9F,MAAM,oBAAoB;EACxB,eAAe,gBAAgBA,mBAAAA,6BAA6B,eAAe,UAAUC,mBAAAA,uBAAuBC,mBAAAA;EAC5G,SAAS,eAAe,aAAaC,mBAAAA,yBAAyB,KAAA;EAC9D,aAAaC,mBAAAA,sBAAsB,KAAA;EACpC,CAAC,QAAQ,MAAkC,QAAQ,EAAE,CAAC;CAEvD,MAAM,aAAa,QAAQ,cAAc;AAEzC,QAAO;EACL,MAAM;EACN,SAA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