@kubb/plugin-zod 5.0.0-alpha.6 → 5.0.0-alpha.8
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.
- package/dist/{generators-CzSLRVqQ.cjs → generators-BjPDdJUz.cjs} +9 -9
- package/dist/generators-BjPDdJUz.cjs.map +1 -0
- package/dist/{generators-CRKtFRi1.js → generators-lTWPS6oN.js} +10 -10
- package/dist/generators-lTWPS6oN.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +3 -3
- package/dist/generators.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/generators/operationsGenerator.tsx +4 -4
- package/src/generators/zodGenerator.tsx +6 -6
- package/src/plugin.ts +4 -4
- package/dist/generators-CRKtFRi1.js.map +0 -1
- package/dist/generators-CzSLRVqQ.cjs.map +0 -1
|
@@ -14,11 +14,11 @@ const operationsGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator
|
|
|
14
14
|
name: "operations",
|
|
15
15
|
Operations({ operations, generator, plugin }) {
|
|
16
16
|
const { name: pluginName, options: { output, importPath } } = plugin;
|
|
17
|
-
const
|
|
17
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
18
18
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
19
19
|
const { getFile, groupSchemasByName } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
20
20
|
const name = "operations";
|
|
21
|
-
const file =
|
|
21
|
+
const file = driver.getFile({
|
|
22
22
|
name,
|
|
23
23
|
extname: ".ts",
|
|
24
24
|
pluginName
|
|
@@ -47,7 +47,7 @@ const operationsGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator
|
|
|
47
47
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
48
48
|
oas,
|
|
49
49
|
output,
|
|
50
|
-
config:
|
|
50
|
+
config: driver.config
|
|
51
51
|
}),
|
|
52
52
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
53
53
|
oas,
|
|
@@ -76,7 +76,7 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
76
76
|
Operation({ config, operation, generator, plugin }) {
|
|
77
77
|
const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, guidType, mini } } = plugin;
|
|
78
78
|
const mode = (0, _kubb_core_hooks.useMode)();
|
|
79
|
-
const
|
|
79
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
80
80
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
81
81
|
const { getSchemas, getFile, getGroup } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
82
82
|
const schemaManager = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
@@ -86,7 +86,7 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
86
86
|
fabric: generator.context.fabric,
|
|
87
87
|
oas,
|
|
88
88
|
plugin,
|
|
89
|
-
|
|
89
|
+
driver,
|
|
90
90
|
events: generator.context.events,
|
|
91
91
|
mode,
|
|
92
92
|
override: options.override
|
|
@@ -183,7 +183,7 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
183
183
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
184
184
|
oas,
|
|
185
185
|
output: plugin.options.output,
|
|
186
|
-
config:
|
|
186
|
+
config: driver.config
|
|
187
187
|
}),
|
|
188
188
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
189
189
|
oas,
|
|
@@ -208,7 +208,7 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
208
208
|
Schema({ config, schema, plugin }) {
|
|
209
209
|
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useSchemaManager)();
|
|
210
210
|
const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini } } = plugin;
|
|
211
|
-
const
|
|
211
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
212
212
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
213
213
|
const imports = (0, _kubb_plugin_oas_utils.getImports)(schema.tree);
|
|
214
214
|
const zod = {
|
|
@@ -232,7 +232,7 @@ const zodGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
232
232
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
233
233
|
oas,
|
|
234
234
|
output,
|
|
235
|
-
config:
|
|
235
|
+
config: driver.config
|
|
236
236
|
}),
|
|
237
237
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
238
238
|
oas,
|
|
@@ -298,4 +298,4 @@ Object.defineProperty(exports, "zodGenerator", {
|
|
|
298
298
|
}
|
|
299
299
|
});
|
|
300
300
|
|
|
301
|
-
//# sourceMappingURL=generators-
|
|
301
|
+
//# sourceMappingURL=generators-BjPDdJUz.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BjPDdJUz.cjs","names":["File","Operations","SchemaGenerator","path","schemaKeywords","pluginTsName","File","Zod"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginDriver } 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 name: pluginName,\n options: { output, importPath },\n } = plugin\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = driver.getFile({ name, extname: '.ts', pluginName })\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 const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginDriver } 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, getImports } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } 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, guidType, mini },\n } = plugin\n\n const mode = useMode()\n const driver = usePluginDriver()\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 driver,\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 const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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 = 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 pluginName: pluginTsName,\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginName: pluginTsName,\n group,\n }),\n }\n\n return (\n <>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\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 guidType={guidType}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </>\n )\n }\n\n const isZodImport = plugin.options.importPath === 'zod' || plugin.options.importPath === 'zod/mini'\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: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={file.path} path={toZodPath} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini },\n } = plugin\n const driver = usePluginDriver()\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', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={zod.file.path} path={toZodPath} />}\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 guidType={guidType}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;AAQA,MAAa,uBAAA,GAAA,4BAAA,sBAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,MAAM,YACN,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,UAAA,GAAA,iBAAA,kBAA0B;EAEhC,MAAM,OAAA,GAAA,uBAAA,SAAc;EACpB,MAAM,EAAE,SAAS,wBAAA,GAAA,uBAAA,qBAA2C,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,OAAO,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAY,CAAC;EAEjE,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,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KAAK;KAAM,MAAM;KAAa,CAAA;IAC7G,QAAQ,KAAK,QACZ,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAkE,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAvG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,KAAD;KACE,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO,KAAA;KAC9B,eAAe,WAAW,IAAI,gBAAgB,KAAA;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACC;KACO;KACX;KACN,CAAA;IACG;;;CAGZ,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { n as Operations, t as Zod } from "./components-eECfXVou.js";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { SchemaGenerator, schemaKeywords } from "@kubb/plugin-oas";
|
|
5
5
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
6
|
-
import { useMode,
|
|
6
|
+
import { useMode, usePluginDriver } from "@kubb/core/hooks";
|
|
7
7
|
import { createReactGenerator } from "@kubb/plugin-oas/generators";
|
|
8
8
|
import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
|
|
9
9
|
import { getBanner, getFooter, getImports } from "@kubb/plugin-oas/utils";
|
|
@@ -14,11 +14,11 @@ const operationsGenerator = createReactGenerator({
|
|
|
14
14
|
name: "operations",
|
|
15
15
|
Operations({ operations, generator, plugin }) {
|
|
16
16
|
const { name: pluginName, options: { output, importPath } } = plugin;
|
|
17
|
-
const
|
|
17
|
+
const driver = usePluginDriver();
|
|
18
18
|
const oas = useOas();
|
|
19
19
|
const { getFile, groupSchemasByName } = useOperationManager(generator);
|
|
20
20
|
const name = "operations";
|
|
21
|
-
const file =
|
|
21
|
+
const file = driver.getFile({
|
|
22
22
|
name,
|
|
23
23
|
extname: ".ts",
|
|
24
24
|
pluginName
|
|
@@ -47,7 +47,7 @@ const operationsGenerator = createReactGenerator({
|
|
|
47
47
|
banner: getBanner({
|
|
48
48
|
oas,
|
|
49
49
|
output,
|
|
50
|
-
config:
|
|
50
|
+
config: driver.config
|
|
51
51
|
}),
|
|
52
52
|
footer: getFooter({
|
|
53
53
|
oas,
|
|
@@ -76,7 +76,7 @@ const zodGenerator = createReactGenerator({
|
|
|
76
76
|
Operation({ config, operation, generator, plugin }) {
|
|
77
77
|
const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, guidType, mini } } = plugin;
|
|
78
78
|
const mode = useMode();
|
|
79
|
-
const
|
|
79
|
+
const driver = usePluginDriver();
|
|
80
80
|
const oas = useOas();
|
|
81
81
|
const { getSchemas, getFile, getGroup } = useOperationManager(generator);
|
|
82
82
|
const schemaManager = useSchemaManager();
|
|
@@ -86,7 +86,7 @@ const zodGenerator = createReactGenerator({
|
|
|
86
86
|
fabric: generator.context.fabric,
|
|
87
87
|
oas,
|
|
88
88
|
plugin,
|
|
89
|
-
|
|
89
|
+
driver,
|
|
90
90
|
events: generator.context.events,
|
|
91
91
|
mode,
|
|
92
92
|
override: options.override
|
|
@@ -183,7 +183,7 @@ const zodGenerator = createReactGenerator({
|
|
|
183
183
|
banner: getBanner({
|
|
184
184
|
oas,
|
|
185
185
|
output: plugin.options.output,
|
|
186
|
-
config:
|
|
186
|
+
config: driver.config
|
|
187
187
|
}),
|
|
188
188
|
footer: getFooter({
|
|
189
189
|
oas,
|
|
@@ -208,7 +208,7 @@ const zodGenerator = createReactGenerator({
|
|
|
208
208
|
Schema({ config, schema, plugin }) {
|
|
209
209
|
const { getName, getFile } = useSchemaManager();
|
|
210
210
|
const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini } } = plugin;
|
|
211
|
-
const
|
|
211
|
+
const driver = usePluginDriver();
|
|
212
212
|
const oas = useOas();
|
|
213
213
|
const imports = getImports(schema.tree);
|
|
214
214
|
const zod = {
|
|
@@ -232,7 +232,7 @@ const zodGenerator = createReactGenerator({
|
|
|
232
232
|
banner: getBanner({
|
|
233
233
|
oas,
|
|
234
234
|
output,
|
|
235
|
-
config:
|
|
235
|
+
config: driver.config
|
|
236
236
|
}),
|
|
237
237
|
footer: getFooter({
|
|
238
238
|
oas,
|
|
@@ -287,4 +287,4 @@ const zodGenerator = createReactGenerator({
|
|
|
287
287
|
//#endregion
|
|
288
288
|
export { operationsGenerator as n, zodGenerator as t };
|
|
289
289
|
|
|
290
|
-
//# sourceMappingURL=generators-
|
|
290
|
+
//# sourceMappingURL=generators-lTWPS6oN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-lTWPS6oN.js","names":[],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginDriver } 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 name: pluginName,\n options: { output, importPath },\n } = plugin\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = driver.getFile({ name, extname: '.ts', pluginName })\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 const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginDriver } 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, getImports } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } 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, guidType, mini },\n } = plugin\n\n const mode = useMode()\n const driver = usePluginDriver()\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 driver,\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 const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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 = 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 pluginName: pluginTsName,\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginName: pluginTsName,\n group,\n }),\n }\n\n return (\n <>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\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 guidType={guidType}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </>\n )\n }\n\n const isZodImport = plugin.options.importPath === 'zod' || plugin.options.importPath === 'zod/mini'\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: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={file.path} path={toZodPath} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini },\n } = plugin\n const driver = usePluginDriver()\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', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={zod.file.path} path={toZodPath} />}\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 guidType={guidType}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;AAQA,MAAa,sBAAsB,qBAAgC;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,MAAM,YACN,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,SAAS,iBAAiB;EAEhC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,uBAAuB,oBAAoB,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,OAAO,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAY,CAAC;EAEjE,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,oBAAC,KAAK,QAAN;IAAuB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;IAAQ,EAApE,IAAoE;IAC7F,CACD,OAAO,QAAQ;EAElB,MAAM,cAAc,eAAe,SAAS,eAAe;AAE3D,SACE,qBAAC,MAAD;GACE,UAA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AN;KAAa,YAAA;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;KAAI,CAAA;IACjG,SAAS,YAAY,OAAO,oBAAC,KAAK,QAAN;KAAa,MAAM,CAAC,QAAQ;KAAE,YAAA;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM;KAAa,CAAA;IAC7G,QAAQ,KAAK,QACZ,oBAAC,KAAK,QAAN;KAAkE,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAvG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,oBAAC,KAAD;KACE,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO,KAAA;KAC9B,eAAe,WAAW,IAAI,gBAAgB,KAAA;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACC;KACO;KACX;KACN,CAAA;IACG;;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-BjPDdJUz.cjs");
|
|
3
3
|
exports.operationsGenerator = require_generators.operationsGenerator;
|
|
4
4
|
exports.zodGenerator = require_generators.zodGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { n as PluginZod } from "./types-CoCoOc2u.js";
|
|
3
|
-
import { AsyncEventEmitter, Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin,
|
|
3
|
+
import { AsyncEventEmitter, Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
4
4
|
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
5
5
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
6
|
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
@@ -105,7 +105,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
105
105
|
include: Array<Include> | undefined;
|
|
106
106
|
override: Array<Override<TOptions>> | undefined;
|
|
107
107
|
contentType: contentType | undefined;
|
|
108
|
-
|
|
108
|
+
driver: PluginDriver;
|
|
109
109
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
110
110
|
/**
|
|
111
111
|
* Current plugin
|
|
@@ -359,7 +359,7 @@ type Schema = {
|
|
|
359
359
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
360
360
|
fabric: Fabric;
|
|
361
361
|
oas: Oas;
|
|
362
|
-
|
|
362
|
+
driver: PluginDriver;
|
|
363
363
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
364
364
|
/**
|
|
365
365
|
* Current plugin
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as operationsGenerator, t as zodGenerator } from "./generators-
|
|
1
|
+
import { n as operationsGenerator, t as zodGenerator } from "./generators-lTWPS6oN.js";
|
|
2
2
|
export { operationsGenerator, zodGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_components = require("./components-B7zUFnAm.cjs");
|
|
3
|
-
const require_generators = require("./generators-
|
|
3
|
+
const require_generators = require("./generators-BjPDdJUz.cjs");
|
|
4
4
|
const require_templates_ToZod_source = require("./templates/ToZod.source.cjs");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
node_path = require_components.__toESM(node_path);
|
|
@@ -64,7 +64,7 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region src/plugin.ts
|
|
66
66
|
const pluginZodName = "plugin-zod";
|
|
67
|
-
const pluginZod = (0, _kubb_core.
|
|
67
|
+
const pluginZod = (0, _kubb_core.createPlugin)((options) => {
|
|
68
68
|
const { output = {
|
|
69
69
|
path: "zod",
|
|
70
70
|
barrelType: "named"
|
|
@@ -138,7 +138,7 @@ const pluginZod = (0, _kubb_core.definePlugin)((options) => {
|
|
|
138
138
|
const schemaFiles = await new _kubb_plugin_oas.SchemaGenerator(this.plugin.options, {
|
|
139
139
|
fabric: this.fabric,
|
|
140
140
|
oas,
|
|
141
|
-
|
|
141
|
+
driver: this.driver,
|
|
142
142
|
events: this.events,
|
|
143
143
|
plugin: this.plugin,
|
|
144
144
|
contentType,
|
|
@@ -151,7 +151,7 @@ const pluginZod = (0, _kubb_core.definePlugin)((options) => {
|
|
|
151
151
|
const operationFiles = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
152
152
|
fabric: this.fabric,
|
|
153
153
|
oas,
|
|
154
|
-
|
|
154
|
+
driver: this.driver,
|
|
155
155
|
events: this.events,
|
|
156
156
|
plugin: this.plugin,
|
|
157
157
|
contentType,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PackageManager","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","path","toZodSource","SchemaGenerator","OperationGenerator"],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\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 { source as toZodSource } from './templates/ToZod.source.ts'\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 integerType = 'number',\n typed = false,\n mapper = {},\n operations = false,\n mini = false,\n version = mini ? '4' : new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n guidType = 'uuid',\n importPath = mini ? 'zod/mini' : 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 // @deprecated Will be removed in v5 when collisionDetection defaults to true\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 integerType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\n guidType,\n mini,\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: toZodSource,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;AAQjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;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AAE/B,OAAI,KAAK,OAAO,QAAQ,SAAS,KAAK,OAAO,QAAQ,YAAY,IAE/D,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAMA,UAAAA,QAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,OAAOC,+BAAAA;KACR,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,cAAc,MAbI,IAAIC,iBAAAA,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PackageManager","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","path","toZodSource","SchemaGenerator","OperationGenerator"],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\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 { source as toZodSource } from './templates/ToZod.source.ts'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<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 integerType = 'number',\n typed = false,\n mapper = {},\n operations = false,\n mini = false,\n version = mini ? '4' : new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n guidType = 'uuid',\n importPath = mini ? 'zod/mini' : 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 // @deprecated Will be removed in v5 when collisionDetection defaults to true\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 integerType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\n guidType,\n mini,\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: toZodSource,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;AAQjC,SAAS,iBA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as zodGenerator } from "./generators-
|
|
2
|
+
import { n as operationsGenerator, t as zodGenerator } from "./generators-lTWPS6oN.js";
|
|
3
3
|
import { source } from "./templates/ToZod.source.js";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { PackageManager,
|
|
5
|
+
import { PackageManager, createPlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
6
6
|
import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
7
7
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
8
8
|
//#region ../../internals/utils/src/casing.ts
|
|
@@ -62,7 +62,7 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/plugin.ts
|
|
64
64
|
const pluginZodName = "plugin-zod";
|
|
65
|
-
const pluginZod =
|
|
65
|
+
const pluginZod = createPlugin((options) => {
|
|
66
66
|
const { output = {
|
|
67
67
|
path: "zod",
|
|
68
68
|
barrelType: "named"
|
|
@@ -136,7 +136,7 @@ const pluginZod = definePlugin((options) => {
|
|
|
136
136
|
const schemaFiles = await new SchemaGenerator(this.plugin.options, {
|
|
137
137
|
fabric: this.fabric,
|
|
138
138
|
oas,
|
|
139
|
-
|
|
139
|
+
driver: this.driver,
|
|
140
140
|
events: this.events,
|
|
141
141
|
plugin: this.plugin,
|
|
142
142
|
contentType,
|
|
@@ -149,7 +149,7 @@ const pluginZod = definePlugin((options) => {
|
|
|
149
149
|
const operationFiles = await new OperationGenerator(this.plugin.options, {
|
|
150
150
|
fabric: this.fabric,
|
|
151
151
|
oas,
|
|
152
|
-
|
|
152
|
+
driver: this.driver,
|
|
153
153
|
events: this.events,
|
|
154
154
|
plugin: this.plugin,
|
|
155
155
|
contentType,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["toZodSource"],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\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 { source as toZodSource } from './templates/ToZod.source.ts'\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 integerType = 'number',\n typed = false,\n mapper = {},\n operations = false,\n mini = false,\n version = mini ? '4' : new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n guidType = 'uuid',\n importPath = mini ? 'zod/mini' : 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 // @deprecated Will be removed in v5 when collisionDetection defaults to true\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 integerType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\n guidType,\n mini,\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: toZodSource,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aA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,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;AAE/B,OAAI,KAAK,OAAO,QAAQ,SAAS,KAAK,OAAO,QAAQ,YAAY,IAE/D,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,OAAOA;KACR,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["toZodSource"],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'\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 { source as toZodSource } from './templates/ToZod.source.ts'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<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 integerType = 'number',\n typed = false,\n mapper = {},\n operations = false,\n mini = false,\n version = mini ? '4' : new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',\n guidType = 'uuid',\n importPath = mini ? 'zod/mini' : 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 // @deprecated Will be removed in v5 when collisionDetection defaults to true\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 integerType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\n guidType,\n mini,\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: toZodSource,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;AAQjC,SAAS,iBAA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AM,KAAK,QAAQ;AAE/B,OAAI,KAAK,OAAO,QAAQ,SAAS,KAAK,OAAO,QAAQ,YAAY,IAE/D,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,iBAAiB;IAC1C,SAAS,CACP;KACE,MAAM;KACN,OAAOA;KACR,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS,KAAA;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.8",
|
|
4
4
|
"description": "Zod schema generator plugin for Kubb, creating type-safe validation schemas from OpenAPI specifications for runtime data validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@kubb/react-fabric": "0.14.0",
|
|
81
81
|
"remeda": "^2.33.6",
|
|
82
|
-
"@kubb/core": "5.0.0-alpha.
|
|
83
|
-
"@kubb/oas": "5.0.0-alpha.
|
|
84
|
-
"@kubb/plugin-oas": "5.0.0-alpha.
|
|
85
|
-
"@kubb/plugin-ts": "5.0.0-alpha.
|
|
82
|
+
"@kubb/core": "5.0.0-alpha.8",
|
|
83
|
+
"@kubb/oas": "5.0.0-alpha.8",
|
|
84
|
+
"@kubb/plugin-oas": "5.0.0-alpha.8",
|
|
85
|
+
"@kubb/plugin-ts": "5.0.0-alpha.8"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@asteasolutions/zod-to-openapi": "^8.4.3",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePluginDriver } from '@kubb/core/hooks'
|
|
2
2
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
3
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
4
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
@@ -13,13 +13,13 @@ export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
|
13
13
|
name: pluginName,
|
|
14
14
|
options: { output, importPath },
|
|
15
15
|
} = plugin
|
|
16
|
-
const
|
|
16
|
+
const driver = usePluginDriver()
|
|
17
17
|
|
|
18
18
|
const oas = useOas()
|
|
19
19
|
const { getFile, groupSchemasByName } = useOperationManager(generator)
|
|
20
20
|
|
|
21
21
|
const name = 'operations'
|
|
22
|
-
const file =
|
|
22
|
+
const file = driver.getFile({ name, extname: '.ts', pluginName })
|
|
23
23
|
|
|
24
24
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))
|
|
25
25
|
|
|
@@ -38,7 +38,7 @@ export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
|
38
38
|
baseName={file.baseName}
|
|
39
39
|
path={file.path}
|
|
40
40
|
meta={file.meta}
|
|
41
|
-
banner={getBanner({ oas, output, config:
|
|
41
|
+
banner={getBanner({ oas, output, config: driver.config })}
|
|
42
42
|
footer={getFooter({ oas, output })}
|
|
43
43
|
>
|
|
44
44
|
<File.Import isTypeOnly name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { useMode,
|
|
2
|
+
import { useMode, usePluginDriver } from '@kubb/core/hooks'
|
|
3
3
|
import { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
4
4
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
5
5
|
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
@@ -18,7 +18,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
18
18
|
} = plugin
|
|
19
19
|
|
|
20
20
|
const mode = useMode()
|
|
21
|
-
const
|
|
21
|
+
const driver = usePluginDriver()
|
|
22
22
|
|
|
23
23
|
const oas = useOas()
|
|
24
24
|
const { getSchemas, getFile, getGroup } = useOperationManager(generator)
|
|
@@ -30,7 +30,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
30
30
|
fabric: generator.context.fabric,
|
|
31
31
|
oas,
|
|
32
32
|
plugin,
|
|
33
|
-
|
|
33
|
+
driver,
|
|
34
34
|
events: generator.context.events,
|
|
35
35
|
mode,
|
|
36
36
|
override: options.override,
|
|
@@ -133,7 +133,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
133
133
|
baseName={file.baseName}
|
|
134
134
|
path={file.path}
|
|
135
135
|
meta={file.meta}
|
|
136
|
-
banner={getBanner({ oas, output: plugin.options.output, config:
|
|
136
|
+
banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}
|
|
137
137
|
footer={getFooter({ oas, output: plugin.options.output })}
|
|
138
138
|
>
|
|
139
139
|
<File.Import name={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />
|
|
@@ -147,7 +147,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
147
147
|
const {
|
|
148
148
|
options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini },
|
|
149
149
|
} = plugin
|
|
150
|
-
const
|
|
150
|
+
const driver = usePluginDriver()
|
|
151
151
|
const oas = useOas()
|
|
152
152
|
|
|
153
153
|
const imports = getImports(schema.tree)
|
|
@@ -171,7 +171,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
171
171
|
baseName={zod.file.baseName}
|
|
172
172
|
path={zod.file.path}
|
|
173
173
|
meta={zod.file.meta}
|
|
174
|
-
banner={getBanner({ oas, output, config:
|
|
174
|
+
banner={getBanner({ oas, output, config: driver.config })}
|
|
175
175
|
footer={getFooter({ oas, output })}
|
|
176
176
|
>
|
|
177
177
|
<File.Import name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase, pascalCase } from '@internals/utils'
|
|
3
|
-
import {
|
|
3
|
+
import { createPlugin, type Group, getBarrelFiles, getMode, PackageManager } from '@kubb/core'
|
|
4
4
|
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
5
5
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
6
|
import { operationsGenerator } from './generators'
|
|
@@ -10,7 +10,7 @@ import type { PluginZod } from './types.ts'
|
|
|
10
10
|
|
|
11
11
|
export const pluginZodName = 'plugin-zod' satisfies PluginZod['name']
|
|
12
12
|
|
|
13
|
-
export const pluginZod =
|
|
13
|
+
export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
14
14
|
const {
|
|
15
15
|
output = { path: 'zod', barrelType: 'named' },
|
|
16
16
|
group,
|
|
@@ -139,7 +139,7 @@ export const pluginZod = definePlugin<PluginZod>((options) => {
|
|
|
139
139
|
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
140
140
|
fabric: this.fabric,
|
|
141
141
|
oas,
|
|
142
|
-
|
|
142
|
+
driver: this.driver,
|
|
143
143
|
events: this.events,
|
|
144
144
|
plugin: this.plugin,
|
|
145
145
|
contentType,
|
|
@@ -155,7 +155,7 @@ export const pluginZod = definePlugin<PluginZod>((options) => {
|
|
|
155
155
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
156
156
|
fabric: this.fabric,
|
|
157
157
|
oas,
|
|
158
|
-
|
|
158
|
+
driver: this.driver,
|
|
159
159
|
events: this.events,
|
|
160
160
|
plugin: this.plugin,
|
|
161
161
|
contentType,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CRKtFRi1.js","names":[],"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 name: pluginName,\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', pluginName })\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 const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\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={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\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, getImports } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } 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, guidType, 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 const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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 = 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 pluginName: pluginTsName,\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginName: pluginTsName,\n group,\n }),\n }\n\n return (\n <>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\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 guidType={guidType}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </>\n )\n }\n\n const isZodImport = plugin.options.importPath === 'zod' || plugin.options.importPath === 'zod/mini'\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={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={file.path} path={toZodPath} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, 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', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={zod.file.path} path={toZodPath} />}\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 guidType={guidType}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;AAQA,MAAa,sBAAsB,qBAAgC;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,MAAM,YACN,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,uBAAuB,oBAAoB,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAY,CAAC;EAExE,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,oBAAC,KAAK,QAAN;IAAuB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;IAAQ,EAApE,IAAoE;IAC7F,CAC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cAAc,MAAM,CAAC,IAAI;KAAE,MAAM;KAAY,aAAa;KAAe,CAAA;IAC3F,SAAS,oBAAC,KAAK,QAAN;KAAa,YAAA;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;KAAI,CAAA;IACjG,SAAS,YAAY,OAAO,oBAAC,KAAK,QAAN;KAAa,MAAM,CAAC,QAAQ;KAAE,YAAA;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM;KAAa,CAAA;IAC7G,QAAQ,KAAK,QACZ,oBAAC,KAAK,QAAN;KAAkE,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAvG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,oBAAC,KAAD;KACE,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO,KAAA;KAC9B,eAAe,WAAW,IAAI,gBAAgB,KAAA;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACC;KACO;KACX;KACN,CAAA;IACG;;;CAGZ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CzSLRVqQ.cjs","names":["File","Operations","SchemaGenerator","path","schemaKeywords","pluginTsName","File","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 name: pluginName,\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', pluginName })\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 const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\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={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\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, getImports } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } 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, guidType, 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 const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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 = 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 pluginName: pluginTsName,\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginName: pluginTsName,\n group,\n }),\n }\n\n return (\n <>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\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 guidType={guidType}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </>\n )\n }\n\n const isZodImport = plugin.options.importPath === 'zod' || plugin.options.importPath === 'zod/mini'\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={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={file.path} path={toZodPath} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, 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', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={zod.file.path} path={toZodPath} />}\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 guidType={guidType}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;AAQA,MAAa,uBAAA,GAAA,4BAAA,sBAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,MAAM,YACN,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,iBAAA,GAAA,iBAAA,mBAAkC;EAExC,MAAM,OAAA,GAAA,uBAAA,SAAc;EACpB,MAAM,EAAE,SAAS,wBAAA,GAAA,uBAAA,qBAA2C,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAY,CAAC;EAExE,MAAM,wBAAwB,WAAW,KAAK,eAAe;GAAE;GAAW,MAAM,mBAAmB,WAAW,EAAE,MAAM,YAAY,CAAC;GAAE,E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