@kubb/plugin-zod 4.18.4 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { c as __name, i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-B5e4IaUY.cjs";
1
+ import { c as __name, i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-DOEZUvN2.cjs";
2
2
  import { KubbFile } from "@kubb/fabric-core/types";
3
3
  import { KubbNode } from "@kubb/react-fabric/types";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-eQyhnF5A.js";
2
- import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-BNtlNlKK.js";
2
+ import { i as Schema, n as PluginZod, o as Operation, s as SchemaObject } from "./types-CgirIjVB.js";
3
3
  import { KubbFile } from "@kubb/fabric-core/types";
4
4
  import { KubbNode } from "@kubb/react-fabric/types";
5
5
 
@@ -99,7 +99,16 @@ const zodGenerator = createReactGenerator({
99
99
  schemas.request,
100
100
  schemas.response
101
101
  ].flat().filter(Boolean);
102
- const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options$1 }) => {
102
+ const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options$1 }) => {
103
+ let schemaObject = schemaOriginal;
104
+ let keysToOmit = keysToOmitOriginal;
105
+ if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {
106
+ schemaObject = structuredClone(schemaOriginal);
107
+ delete schemaObject.$ref;
108
+ for (const key of keysToOmitOriginal) delete schemaObject.properties?.[key];
109
+ if (Array.isArray(schemaObject.required)) schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key));
110
+ keysToOmit = void 0;
111
+ }
103
112
  const hasProperties = Object.keys(schemaObject || {}).length > 0;
104
113
  const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
105
114
  const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
@@ -265,4 +274,4 @@ const zodGenerator = createReactGenerator({
265
274
 
266
275
  //#endregion
267
276
  export { operationsGenerator as n, zodGenerator as t };
268
- //# sourceMappingURL=generators-BP4elkVx.js.map
277
+ //# sourceMappingURL=generators-BIWiaBYS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-BIWiaBYS.js","names":["options"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, mini },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n pluginManager,\n events: generator.context.events,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }: OperationSchemaType) => {\n let schemaObject = schemaOriginal\n let keysToOmit = keysToOmitOriginal\n\n if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {\n schemaObject = structuredClone(schemaOriginal)\n\n // Remove $ref so the schema parser generates inline schema instead of a reference\n delete schemaObject.$ref\n\n for (const key of keysToOmitOriginal) {\n delete schemaObject.properties?.[key]\n }\n\n if (Array.isArray(schemaObject.required)) {\n schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key))\n }\n\n keysToOmit = undefined\n }\n\n const hasProperties = Object.keys(schemaObject || {}).length > 0\n const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))\n\n const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required\n const optional = !required && !hasDefaults && hasProperties && name.includes('Params')\n\n if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {\n schemaObject.required = Object.entries(schemaObject.properties || {})\n .filter(([_key, value]) => value && Object.hasOwn(value, 'default'))\n .map(([key]) => key)\n }\n\n const tree = [\n ...schemaGenerator.parse({ schema: schemaObject, name, parentName: null }),\n optional ? { keyword: schemaKeywords.optional } : undefined,\n ].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </Fragment>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, mini },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAQA,MAAa,sBAAsB,qBAAgC;CACjE,MAAM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AO,MAAM,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC;GAC1D;AAED,SACE,qBAAC;GACC,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;;IAElC,oBAAC,KAAK;KAAO,MAAM,CAAC,IAAI;KAAE,MAAM;MAAc;IAC7C,SAAS,oBAAC,KAAK;KAAO;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;MAAI;IACjG,SAAS,YAAY,OACpB,oBAAC,KAAK;KAAO,MAAM,CAAC,QAAQ;KAAE,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,iBAAiB;MAAI;IAE7H,QAAQ,KAAK,QACZ,oBAAC,KAAK;KAA4D,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;OAA/F;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,oBAAC;KACC,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO;KAC9B,eAAe,WAAW,IAAI,gBAAgB;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACQ;KACX;MACN;;IACG;;CAGZ,CAAC"}
@@ -99,7 +99,16 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
99
99
  schemas.request,
100
100
  schemas.response
101
101
  ].flat().filter(Boolean);
102
- const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options$1 }) => {
102
+ const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options$1 }) => {
103
+ let schemaObject = schemaOriginal;
104
+ let keysToOmit = keysToOmitOriginal;
105
+ if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {
106
+ schemaObject = structuredClone(schemaOriginal);
107
+ delete schemaObject.$ref;
108
+ for (const key of keysToOmitOriginal) delete schemaObject.properties?.[key];
109
+ if (Array.isArray(schemaObject.required)) schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key));
110
+ keysToOmit = void 0;
111
+ }
103
112
  const hasProperties = Object.keys(schemaObject || {}).length > 0;
104
113
  const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
105
114
  const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
@@ -276,4 +285,4 @@ Object.defineProperty(exports, 'zodGenerator', {
276
285
  return zodGenerator;
277
286
  }
278
287
  });
279
- //# sourceMappingURL=generators-CCbjEMCj.cjs.map
288
+ //# sourceMappingURL=generators-boBB_r4u.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-boBB_r4u.cjs","names":["File","Operations","SchemaGenerator","options","schemaKeywords","pluginTsName","Fragment","File","path","Zod"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, mini },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n pluginManager,\n events: generator.context.events,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }: OperationSchemaType) => {\n let schemaObject = schemaOriginal\n let keysToOmit = keysToOmitOriginal\n\n if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {\n schemaObject = structuredClone(schemaOriginal)\n\n // Remove $ref so the schema parser generates inline schema instead of a reference\n delete schemaObject.$ref\n\n for (const key of keysToOmitOriginal) {\n delete schemaObject.properties?.[key]\n }\n\n if (Array.isArray(schemaObject.required)) {\n schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key))\n }\n\n keysToOmit = undefined\n }\n\n const hasProperties = Object.keys(schemaObject || {}).length > 0\n const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))\n\n const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required\n const optional = !required && !hasDefaults && hasProperties && name.includes('Params')\n\n if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {\n schemaObject.required = Object.entries(schemaObject.properties || {})\n .filter(([_key, value]) => value && Object.hasOwn(value, 'default'))\n .map(([key]) => key)\n }\n\n const tree = [\n ...schemaGenerator.parse({ schema: schemaObject, name, parentName: null }),\n optional ? { keyword: schemaKeywords.optional } : undefined,\n ].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </Fragment>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, mini },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAQA,MAAa,4EAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,wDAAkC;EAExC,MAAM,0CAAc;EACpB,MAAM,EAAE,SAAS,uEAA2C,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAW,CAAC;EAEvE,MAAM,wBAAwB,WAAW,KAAK,eAAe;GAAE;GAAW,MAAM,mBAAmB,WAAW,EAAE,MAAM,YAAY,CAAC;GAAE,EAAE;EAEvI,MAAM,UAAU,OAAO,QAAQ,sBAAsB,CAClD,KAAK,CAAC,KAAK,EAAE,MAAM,iBAAiB;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WAAW;IAAC,CAAC,OAAO,QAAQ;AAEjH,UAAO,wDAACA,wBAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;IAC7F,CACD,OAAO,QAAQ;AAElB,SACE,yDAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,8CAAkB;IAAE;IAA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C1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACQ;KACX;MACN;;IACG;;CAGZ,CAAC"}
@@ -1,4 +1,4 @@
1
- const require_generators = require('./generators-CCbjEMCj.cjs');
1
+ const require_generators = require('./generators-boBB_r4u.cjs');
2
2
 
3
3
  exports.operationsGenerator = require_generators.operationsGenerator;
4
4
  exports.zodGenerator = require_generators.zodGenerator;
@@ -1,4 +1,4 @@
1
- import { c as __name, n as PluginZod, r as ReactGenerator } from "./types-B5e4IaUY.cjs";
1
+ import { c as __name, n as PluginZod, r as ReactGenerator } from "./types-DOEZUvN2.cjs";
2
2
 
3
3
  //#region src/generators/operationsGenerator.d.ts
4
4
  declare const operationsGenerator: ReactGenerator<PluginZod>;
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-eQyhnF5A.js";
2
- import { n as PluginZod, r as ReactGenerator } from "./types-BNtlNlKK.js";
2
+ import { n as PluginZod, r as ReactGenerator } from "./types-CgirIjVB.js";
3
3
 
4
4
  //#region src/generators/operationsGenerator.d.ts
5
5
  declare const operationsGenerator: ReactGenerator<PluginZod>;
@@ -1,3 +1,3 @@
1
- import { n as operationsGenerator, t as zodGenerator } from "./generators-BP4elkVx.js";
1
+ import { n as operationsGenerator, t as zodGenerator } from "./generators-BIWiaBYS.js";
2
2
 
3
3
  export { operationsGenerator, zodGenerator };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_components = require('./components-BKoSLPE6.cjs');
2
- const require_generators = require('./generators-CCbjEMCj.cjs');
2
+ const require_generators = require('./generators-boBB_r4u.cjs');
3
3
  let node_path = require("node:path");
4
4
  node_path = require_components.__toESM(node_path);
5
5
  let _kubb_core = require("@kubb/core");
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UserPluginWithLifeCycle, c as __name, n as PluginZod, t as Options } from "./types-B5e4IaUY.cjs";
1
+ import { a as UserPluginWithLifeCycle, c as __name, n as PluginZod, t as Options } from "./types-DOEZUvN2.cjs";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginZodName = "plugin-zod";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-eQyhnF5A.js";
2
- import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-BNtlNlKK.js";
2
+ import { a as UserPluginWithLifeCycle, n as PluginZod, t as Options } from "./types-CgirIjVB.js";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  declare const pluginZodName = "plugin-zod";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-eQyhnF5A.js";
2
- import { n as operationsGenerator, t as zodGenerator } from "./generators-BP4elkVx.js";
2
+ import { n as operationsGenerator, t as zodGenerator } from "./generators-BIWiaBYS.js";
3
3
  import path from "node:path";
4
4
  import { PackageManager, definePlugin, getBarrelFiles, getMode } from "@kubb/core";
5
5
  import { camelCase, pascalCase } from "@kubb/core/transformers";
@@ -19,16 +19,21 @@ type Operation$1 = Operation;
19
19
  type DiscriminatorObject$1 = DiscriminatorObject;
20
20
  //#endregion
21
21
  //#region ../oas/src/Oas.d.ts
22
- type Options$2 = {
22
+ type OasOptions = {
23
23
  contentType?: contentType;
24
24
  discriminator?: 'strict' | 'inherit';
25
+ /**
26
+ * Resolve name collisions when schemas from different components share the same name (case-insensitive).
27
+ * @default false
28
+ */
29
+ collisionDetection?: boolean;
25
30
  };
26
31
  declare class Oas extends BaseOas {
27
32
  #private;
28
33
  document: Document;
29
34
  constructor(document: Document);
30
- setOptions(options: Options$2): void;
31
- get options(): Options$2;
35
+ setOptions(options: OasOptions): void;
36
+ get options(): OasOptions;
32
37
  get<T = unknown>($ref: string): T | null;
33
38
  getKey($ref: string): string | undefined;
34
39
  set($ref: string, value: unknown): false | undefined;
@@ -37,8 +42,20 @@ declare class Oas extends BaseOas {
37
42
  getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
38
43
  getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
39
44
  getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
40
- valdiate(): Promise<oas_normalize_lib_types0.ValidationResult>;
45
+ validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
41
46
  flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
47
+ /**
48
+ * Get schemas from OpenAPI components (schemas, responses, requestBodies).
49
+ * Returns schemas in dependency order along with name mapping for collision resolution.
50
+ */
51
+ getSchemas(options?: {
52
+ contentType?: contentType;
53
+ includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
54
+ collisionDetection?: boolean;
55
+ }): {
56
+ schemas: Record<string, SchemaObject$1>;
57
+ nameMapping: Map<string, string>;
58
+ };
42
59
  }
43
60
  //#endregion
44
61
  //#region ../core/src/BaseGenerator.d.ts
@@ -339,7 +356,7 @@ type Config<TInput = Input> = {
339
356
  input: TInput;
340
357
  output: {
341
358
  /**
342
- * The path where all generated files will be exported.
359
+ * The path where all generated files receives exported.
343
360
  * This can be an absolute path or a path relative to the specified root option.
344
361
  */
345
362
  path: string;
@@ -354,41 +371,39 @@ type Config<TInput = Input> = {
354
371
  write?: boolean;
355
372
  /**
356
373
  * Specifies the formatting tool to be used.
357
- * @default prettier
358
- *
359
- * Possible values:
360
- * - 'auto': Automatically detects and uses biome or prettier (in that order of preference).
361
- * - 'prettier': Uses Prettier for code formatting.
362
- * - 'biome': Uses Biome for code formatting.
363
- *
374
+ * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
375
+ * - 'prettier' uses Prettier for code formatting.
376
+ * - 'biome' uses Biome for code formatting.
377
+ * - 'oxfmt' uses Oxfmt for code formatting.
378
+ * - false disables code formatting.
379
+ * @default 'prettier'
364
380
  */
365
381
  format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
366
382
  /**
367
383
  * Specifies the linter that should be used to analyze the code.
368
- * The accepted values indicate different linting tools.
369
- *
370
- * Possible values:
371
- * - 'auto': Automatically detects and uses biome, oxlint, or eslint (in that order of preference).
372
- * - 'eslint': Represents the use of ESLint, a widely used JavaScript linter.
373
- * - 'biome': Represents the Biome linter, a modern tool for code scanning.
374
- * - 'oxlint': Represents the Oxlint tool for linting purposes.
375
- *
384
+ * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
385
+ * - 'eslint' uses ESLint for linting.
386
+ * - 'biome' uses Biome for linting.
387
+ * - 'oxlint' uses Oxlint for linting.
388
+ * - false disables linting.
389
+ * @default 'auto'
376
390
  */
377
391
  lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
378
392
  /**
379
- * Override the extension to the generated imports and exports, by default each plugin will add an extension
393
+ * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
380
394
  * @default { '.ts': '.ts'}
381
395
  */
382
396
  extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
383
397
  /**
384
- * Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
398
+ * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
385
399
  * @default 'named'
386
400
  */
387
401
  barrelType?: Exclude<BarrelType, 'propagate'> | false;
388
402
  /**
389
- * Add a default banner to the beginning of every generated file. This makes it clear that the file was generated by Kubb.
390
- * - 'simple': will only add banner with link to Kubb
391
- * - 'full': will add source, title, description and the OpenAPI version used
403
+ * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
404
+ * - 'simple' adds banner with link to Kubb.
405
+ * - 'full' adds source, title, description, and OpenAPI version.
406
+ * - false disables banner generation.
392
407
  * @default 'simple'
393
408
  */
394
409
  defaultBanner?: 'simple' | 'full' | false;
@@ -401,17 +416,17 @@ type Config<TInput = Input> = {
401
416
  override?: boolean;
402
417
  };
403
418
  /**
404
- * An array of Kubb plugins that will be used in the generation.
419
+ * An array of Kubb plugins that used in the generation.
405
420
  * Each plugin may include additional configurable options(defined in the plugin itself).
406
- * If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
421
+ * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
407
422
  */
408
423
  plugins?: Array<Plugin>;
409
424
  /**
410
- * Hooks that will be called when a specific action is triggered in Kubb.
425
+ * Hooks triggered when a specific action occurs in Kubb.
411
426
  */
412
427
  hooks?: {
413
428
  /**
414
- * Hook that will be triggered at the end of all executions.
429
+ * Hook that triggers at the end of all executions.
415
430
  * Useful for running Prettier or ESLint to format/lint your code.
416
431
  */
417
432
  done?: string | Array<string>;
@@ -440,7 +455,7 @@ TContext = any,
440
455
  TResolvePathOptions extends object = object> = {
441
456
  name: TName;
442
457
  /**
443
- * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
458
+ * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
444
459
  */
445
460
  key: PluginKey<TName | string>;
446
461
  options: TOptions;
@@ -461,12 +476,12 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
461
476
  */
462
477
  options: TOptions['resolvedOptions'];
463
478
  /**
464
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
479
+ * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
465
480
  * Can be used to validate dependent plugins.
466
481
  */
467
482
  pre?: Array<string>;
468
483
  /**
469
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
484
+ * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
470
485
  */
471
486
  post?: Array<string>;
472
487
  inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
@@ -484,12 +499,12 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
484
499
  */
485
500
  key: TOptions['key'];
486
501
  /**
487
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
502
+ * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
488
503
  * Can be used to validate dependent plugins.
489
504
  */
490
505
  pre?: Array<string>;
491
506
  /**
492
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
507
+ * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
493
508
  */
494
509
  post?: Array<string>;
495
510
  /**
@@ -539,10 +554,12 @@ type ResolveNameParams = {
539
554
  name: string;
540
555
  pluginKey?: Plugin['key'];
541
556
  /**
542
- * `file` will be used to customize the name of the created file(use of camelCase)
543
- * `function` can be used to customize the exported functions(use of camelCase)
544
- * `type` is a special type for TypeScript(use of PascalCase)
545
- * `const` can be used for variables(use of camelCase)
557
+ * Specifies the type of entity being named.
558
+ * - 'file' customizes the name of the created file (uses camelCase).
559
+ * - 'function' customizes the exported function names (uses camelCase).
560
+ * - 'type' customizes TypeScript types (uses PascalCase).
561
+ * - 'const' customizes variable names (uses camelCase).
562
+ * @default undefined
546
563
  */
547
564
  type?: 'file' | 'function' | 'type' | 'const';
548
565
  };
@@ -597,11 +614,14 @@ type GroupContext = {
597
614
  };
598
615
  type Group = {
599
616
  /**
600
- * Define a type where to group the files on
617
+ * Defines the type where to group the files.
618
+ * - 'tag' groups files by OpenAPI tags.
619
+ * - 'path' groups files by OpenAPI paths.
620
+ * @default undefined
601
621
  */
602
622
  type: 'tag' | 'path';
603
623
  /**
604
- * Return the name of a group based on the group name, this will be used for the file and name generation
624
+ * Return the name of a group based on the group name, this used for the file and name generation
605
625
  */
606
626
  name?: (context: GroupContext) => string;
607
627
  };
@@ -673,7 +693,7 @@ declare class PluginManager {
673
693
  parameters: PluginParameter<H>;
674
694
  }): Array<ReturnType<ParseResult<H>>> | null;
675
695
  /**
676
- * First non-null result stops and will return it's value.
696
+ * Returns the first non-null result.
677
697
  */
678
698
  hookFirst<H extends PluginLifecycleHooks>({
679
699
  hookName,
@@ -685,7 +705,7 @@ declare class PluginManager {
685
705
  skipped?: ReadonlySet<Plugin> | null;
686
706
  }): Promise<SafeParseResult<H>>;
687
707
  /**
688
- * First non-null result stops and will return it's value.
708
+ * Returns the first non-null result.
689
709
  */
690
710
  hookFirstSync<H extends PluginLifecycleHooks>({
691
711
  hookName,
@@ -697,15 +717,15 @@ declare class PluginManager {
697
717
  skipped?: ReadonlySet<Plugin> | null;
698
718
  }): SafeParseResult<H>;
699
719
  /**
700
- * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
720
+ * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
701
721
  */
702
- hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
722
+ hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
703
723
  hookName,
704
724
  parameters
705
725
  }: {
706
726
  hookName: H;
707
727
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
708
- }): Promise<Awaited<TOuput>[]>;
728
+ }): Promise<Awaited<TOutput>[]>;
709
729
  /**
710
730
  * Chains plugins
711
731
  */
@@ -841,8 +861,8 @@ type SchemaKeywordMapper = {
841
861
  */
842
862
  path: KubbFile.Path;
843
863
  /**
844
- * When true `File.Import` will be used.
845
- * When false a reference will be used inside the current file.
864
+ * When true `File.Import` is used.
865
+ * When false a reference is used inside the current file.
846
866
  */
847
867
  isImportable: boolean;
848
868
  };
@@ -1074,7 +1094,7 @@ type SchemaGeneratorOptions = {
1074
1094
  */
1075
1095
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
1076
1096
  /**
1077
- * Receive schema and name(propertName) and return FakerMeta array
1097
+ * Receive schema and name(propertyName) and return FakerMeta array
1078
1098
  * TODO TODO add docs
1079
1099
  * @beta
1080
1100
  */
@@ -1185,7 +1205,7 @@ type Options = {
1185
1205
  output?: Output<Oas>;
1186
1206
  /**
1187
1207
  * Define which contentType should be used.
1188
- * By default, the first JSON valid mediaType will be used
1208
+ * By default, the first JSON valid mediaType is used
1189
1209
  */
1190
1210
  contentType?: contentType;
1191
1211
  /**
@@ -1206,25 +1226,36 @@ type Options = {
1206
1226
  override?: Array<Override<ResolvedOptions>>;
1207
1227
  /**
1208
1228
  * Path to Zod
1209
- * It will be used as `import { z } from '${importPath}'`.
1210
- * It allows both relative and absolute path.
1211
- * the path will be applied as is, so relative path should be based on the file being generated.
1229
+ * It used as `import { z } from '${importPath}'`.
1230
+ * Accepts relative and absolute paths.
1231
+ * Path is used as-is; relative paths are based on the generated file location.
1212
1232
  * @default 'zod'
1213
1233
  */
1214
1234
  importPath?: string;
1215
1235
  /**
1216
- * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
1217
- * False will fallback on a simple z.string() format
1218
- * @default 'string' 'stringOffset' will become the default in Kubb v3
1236
+ * Choose to use date or datetime as JavaScript Date instead of string.
1237
+ * - false falls back to a simple z.string() format.
1238
+ * - 'string' uses z.string().datetime() for datetime validation.
1239
+ * - 'stringOffset' uses z.string().datetime({ offset: true }) for datetime with timezone offset validation.
1240
+ * - 'stringLocal' uses z.string().datetime({ local: true }) for local datetime validation.
1241
+ * - 'date' uses z.date() for JavaScript Date objects.
1242
+ * @default 'string'
1243
+ * @note 'stringOffset' will become the default in Kubb v3.
1219
1244
  */
1220
1245
  dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
1221
1246
  /**
1222
- * Which type to use when the Swagger/OpenAPI file is not providing more information
1247
+ * Which type to use when the Swagger/OpenAPI file is not providing more information.
1248
+ * - 'any' allows any value.
1249
+ * - 'unknown' requires type narrowing before use.
1250
+ * - 'void' represents no value.
1223
1251
  * @default 'any'
1224
1252
  */
1225
1253
  unknownType?: 'any' | 'unknown' | 'void';
1226
1254
  /**
1227
- * Which type to use for empty schema values
1255
+ * Which type to use for empty schema values.
1256
+ * - 'any' allows any value.
1257
+ * - 'unknown' requires type narrowing before use.
1258
+ * - 'void' represents no value.
1228
1259
  * @default `unknownType`
1229
1260
  */
1230
1261
  emptySchemaType?: 'any' | 'unknown' | 'void';
@@ -1253,7 +1284,7 @@ type Options = {
1253
1284
  */
1254
1285
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
1255
1286
  /**
1256
- * Receive schema and baseName(propertName) and return FakerMeta array
1287
+ * Receive schema and baseName(propertyName) and return FakerMeta array
1257
1288
  * TODO TODO add docs
1258
1289
  * @beta
1259
1290
  */
@@ -1264,14 +1295,16 @@ type Options = {
1264
1295
  }, defaultSchemas: Schema[]) => Schema[] | undefined;
1265
1296
  };
1266
1297
  /**
1267
- * Which version of Zod should be used
1268
- * @default '3
1298
+ * Which version of Zod should be used.
1299
+ * - '3' uses Zod v3.x syntax and features.
1300
+ * - '4' uses Zod v4.x syntax and features.
1301
+ * @default '3'
1269
1302
  */
1270
1303
  version?: '3' | '4';
1271
1304
  /**
1272
1305
  * Use Zod Mini's functional API for better tree-shaking support.
1273
1306
  * When enabled, generates functional syntax (e.g., `z.optional(z.string())`) instead of chainable methods (e.g., `z.string().optional()`).
1274
- * Requires Zod v4 or later. When `mini: true`, `version` will be set to '4' and `importPath` will default to 'zod/mini'.
1307
+ * Requires Zod v4 or later. When `mini: true`, `version` is set to '4' and `importPath` will default to 'zod/mini'.
1275
1308
  * @default false
1276
1309
  */
1277
1310
  mini?: boolean;
@@ -1312,4 +1345,4 @@ type ResolvedOptions = {
1312
1345
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
1313
1346
  //#endregion
1314
1347
  export { UserPluginWithLifeCycle as a, Schema as i, PluginZod as n, Operation$1 as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
1315
- //# sourceMappingURL=types-BNtlNlKK.d.ts.map
1348
+ //# sourceMappingURL=types-CgirIjVB.d.ts.map