{"version":3,"file":"index.cjs","names":["PackageManager","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","path","options","groupName: Group['name']","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = definePlugin<PluginZod>((options) => {\n  const {\n    output = { path: 'zod', barrelType: 'named' },\n    group,\n    exclude = [],\n    include,\n    override = [],\n    transformers = {},\n    dateType = 'string',\n    unknownType = 'any',\n    emptySchemaType = unknownType,\n    typed = false,\n    mapper = {},\n    operations = false,\n    version = new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n    importPath = version === '4' ? 'zod/v4' : 'zod',\n    coercion = false,\n    inferred = false,\n    generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n    wrapOutput = undefined,\n    contentType,\n  } = options\n\n  const usedEnumNames = {}\n\n  return {\n    name: pluginZodName,\n    options: {\n      output,\n      transformers,\n      include,\n      exclude,\n      override,\n      typed,\n      dateType,\n      unknownType,\n      emptySchemaType,\n      mapper,\n      importPath,\n      coercion,\n      operations,\n      inferred,\n      group,\n      wrapOutput,\n      version,\n      usedEnumNames,\n    },\n    pre: [pluginOasName, typed ? pluginTsName : 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      let resolvedName = camelCase(name, {\n        suffix: type ? 'schema' : undefined,\n        isFile: type === 'file',\n      })\n\n      if (type === 'type') {\n        resolvedName = pascalCase(resolvedName)\n      }\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\n      if (this.plugin.options.typed && this.plugin.options.version === '3') {\n        // pre add bundled\n        await this.addFile({\n          baseName: 'ToZod.ts',\n          path: path.resolve(root, '.kubb/ToZod.ts'),\n          sources: [\n            {\n              name: 'ToZod',\n              value: resolveModuleSource('@kubb/plugin-zod/templates/ToZod').source,\n            },\n          ],\n        })\n      }\n\n      const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n        fabric: this.fabric,\n        oas,\n        pluginManager: this.pluginManager,\n        plugin: this.plugin,\n        contentType,\n        include: undefined,\n        override,\n        mode,\n        output: output.path,\n      })\n\n      const schemaFiles = await schemaGenerator.build(...generators)\n      await this.addFile(...schemaFiles)\n\n      const operationGenerator = new OperationGenerator(this.plugin.options, {\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      const operationFiles = await operationGenerator.build(...generators)\n      await this.addFile(...operationFiles)\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":";;;;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAO,YAAY;EAAS,EAC7C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,UACX,cAAc,OACd,kBAAkB,aAClB,QAAQ,OACR,SAAS,EAAE,EACX,aAAa,OACb,UAAU,IAAIA,4BAAgB,CAAC,YAAY,OAAO,MAAM,GAAG,MAAM,KACjE,aAAa,YAAY,MAAM,WAAW,OAC1C,WAAW,OACX,WAAW,OACX,aAAa,CAACC,iCAAc,aAAaC,yCAAsB,OAAU,CAAC,OAAO,QAAQ,EACzF,aAAa,QACb,gBACE;AAIJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,eAtBkB,EAAE;GAuBrB;EACD,KAAK,CAACC,iCAAe,QAAQC,gCAAe,OAAU,CAAC,OAAO,QAAQ;EACtE,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,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