@kubb/plugin-zod 5.0.0-alpha.25 → 5.0.0-alpha.27
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/index.cjs +175 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +165 -76
- package/dist/index.js +176 -192
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Zod.tsx +10 -9
- package/src/generators/zodGenerator.tsx +28 -52
- package/src/generators/zodGeneratorLegacy.tsx +27 -51
- package/src/index.ts +2 -1
- package/src/plugin.ts +9 -5
- package/src/presets.ts +7 -2
- package/src/printers/printerZod.ts +31 -4
- package/src/printers/printerZodMini.ts +32 -5
- package/src/resolvers/resolverZod.ts +12 -22
- package/src/resolvers/resolverZodLegacy.ts +8 -8
- package/src/types.ts +56 -17
- package/src/components/ZodMini.tsx +0 -41
package/dist/index.cjs
CHANGED
|
@@ -224,6 +224,39 @@ function Operations({ name, operations }) {
|
|
|
224
224
|
] });
|
|
225
225
|
}
|
|
226
226
|
//#endregion
|
|
227
|
+
//#region src/components/Zod.tsx
|
|
228
|
+
function Zod({ name, node, printer, inferTypeName }) {
|
|
229
|
+
const output = printer.print(node);
|
|
230
|
+
if (!output) return;
|
|
231
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
232
|
+
name,
|
|
233
|
+
isExportable: true,
|
|
234
|
+
isIndexable: true,
|
|
235
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
|
|
236
|
+
export: true,
|
|
237
|
+
name,
|
|
238
|
+
children: output
|
|
239
|
+
})
|
|
240
|
+
}), inferTypeName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
241
|
+
name: inferTypeName,
|
|
242
|
+
isExportable: true,
|
|
243
|
+
isIndexable: true,
|
|
244
|
+
isTypeOnly: true,
|
|
245
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
|
|
246
|
+
export: true,
|
|
247
|
+
name: inferTypeName,
|
|
248
|
+
children: `z.infer<typeof ${name}>`
|
|
249
|
+
})
|
|
250
|
+
})] });
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/constants.ts
|
|
254
|
+
/**
|
|
255
|
+
* Import paths that use a namespace import (`import * as z from '...'`).
|
|
256
|
+
* All other import paths use a named import (`import { z } from '...'`).
|
|
257
|
+
*/
|
|
258
|
+
const ZOD_NAMESPACE_IMPORTS = new Set(["zod", "zod/mini"]);
|
|
259
|
+
//#endregion
|
|
227
260
|
//#region src/utils.ts
|
|
228
261
|
/**
|
|
229
262
|
* Returns `true` when the given coercion option enables coercion for the specified type.
|
|
@@ -552,7 +585,8 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
552
585
|
if (transformed) base = `${base}.and(${transformed})`;
|
|
553
586
|
}
|
|
554
587
|
return base;
|
|
555
|
-
}
|
|
588
|
+
},
|
|
589
|
+
...options.nodes
|
|
556
590
|
},
|
|
557
591
|
print(node) {
|
|
558
592
|
const { keysToOmit } = this.options;
|
|
@@ -572,39 +606,6 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
572
606
|
};
|
|
573
607
|
});
|
|
574
608
|
//#endregion
|
|
575
|
-
//#region src/components/Zod.tsx
|
|
576
|
-
function Zod({ name, node, coercion, guidType, wrapOutput, inferTypeName, resolver, keysToOmit }) {
|
|
577
|
-
const output = printerZod({
|
|
578
|
-
coercion,
|
|
579
|
-
guidType,
|
|
580
|
-
wrapOutput,
|
|
581
|
-
resolver,
|
|
582
|
-
schemaName: name,
|
|
583
|
-
keysToOmit
|
|
584
|
-
}).print(node);
|
|
585
|
-
if (!output) return;
|
|
586
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
587
|
-
name,
|
|
588
|
-
isExportable: true,
|
|
589
|
-
isIndexable: true,
|
|
590
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
|
|
591
|
-
export: true,
|
|
592
|
-
name,
|
|
593
|
-
children: output
|
|
594
|
-
})
|
|
595
|
-
}), inferTypeName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
596
|
-
name: inferTypeName,
|
|
597
|
-
isExportable: true,
|
|
598
|
-
isIndexable: true,
|
|
599
|
-
isTypeOnly: true,
|
|
600
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
|
|
601
|
-
export: true,
|
|
602
|
-
name: inferTypeName,
|
|
603
|
-
children: `z.infer<typeof ${name}>`
|
|
604
|
-
})
|
|
605
|
-
})] });
|
|
606
|
-
}
|
|
607
|
-
//#endregion
|
|
608
609
|
//#region src/printers/printerZodMini.ts
|
|
609
610
|
/**
|
|
610
611
|
* Zod v4 **Mini** printer built with `definePrinter`.
|
|
@@ -756,7 +757,8 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
756
757
|
if (transformed) base = `z.intersection(${base}, ${transformed})`;
|
|
757
758
|
}
|
|
758
759
|
return base;
|
|
759
|
-
}
|
|
760
|
+
},
|
|
761
|
+
...options.nodes
|
|
760
762
|
},
|
|
761
763
|
print(node) {
|
|
762
764
|
const { keysToOmit } = this.options;
|
|
@@ -775,58 +777,19 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
775
777
|
};
|
|
776
778
|
});
|
|
777
779
|
//#endregion
|
|
778
|
-
//#region src/components/ZodMini.tsx
|
|
779
|
-
function ZodMini({ name, node, guidType, wrapOutput, inferTypeName, resolver, keysToOmit }) {
|
|
780
|
-
const output = printerZodMini({
|
|
781
|
-
guidType,
|
|
782
|
-
wrapOutput,
|
|
783
|
-
resolver,
|
|
784
|
-
schemaName: name,
|
|
785
|
-
keysToOmit
|
|
786
|
-
}).print(node);
|
|
787
|
-
if (!output) return;
|
|
788
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
789
|
-
name,
|
|
790
|
-
isExportable: true,
|
|
791
|
-
isIndexable: true,
|
|
792
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
|
|
793
|
-
export: true,
|
|
794
|
-
name,
|
|
795
|
-
children: output
|
|
796
|
-
})
|
|
797
|
-
}), inferTypeName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
798
|
-
name: inferTypeName,
|
|
799
|
-
isExportable: true,
|
|
800
|
-
isIndexable: true,
|
|
801
|
-
isTypeOnly: true,
|
|
802
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Type, {
|
|
803
|
-
export: true,
|
|
804
|
-
name: inferTypeName,
|
|
805
|
-
children: `z.infer<typeof ${name}>`
|
|
806
|
-
})
|
|
807
|
-
})] });
|
|
808
|
-
}
|
|
809
|
-
//#endregion
|
|
810
|
-
//#region src/constants.ts
|
|
811
|
-
/**
|
|
812
|
-
* Import paths that use a namespace import (`import * as z from '...'`).
|
|
813
|
-
* All other import paths use a named import (`import { z } from '...'`).
|
|
814
|
-
*/
|
|
815
|
-
const ZOD_NAMESPACE_IMPORTS = new Set(["zod", "zod/mini"]);
|
|
816
|
-
//#endregion
|
|
817
780
|
//#region src/generators/zodGenerator.tsx
|
|
818
781
|
const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
819
782
|
name: "zod",
|
|
820
783
|
type: "react",
|
|
821
|
-
Schema({ node, adapter, options, config, resolver }) {
|
|
822
|
-
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group,
|
|
823
|
-
const transformedNode = (0, _kubb_ast.transform)(node,
|
|
784
|
+
Schema({ node, adapter, options, config, resolver, plugin }) {
|
|
785
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = options;
|
|
786
|
+
const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
|
|
824
787
|
if (!transformedNode.name) return;
|
|
825
788
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
826
789
|
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
827
790
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
828
791
|
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
829
|
-
name: resolver.
|
|
792
|
+
name: resolver.resolveSchemaName(schemaName),
|
|
830
793
|
path: resolver.resolveFile({
|
|
831
794
|
name: schemaName,
|
|
832
795
|
extname: ".ts"
|
|
@@ -836,9 +799,8 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
836
799
|
group
|
|
837
800
|
}).path
|
|
838
801
|
}));
|
|
839
|
-
const inferTypeName = inferred ? resolver.resolveInferName(resolver.resolveName(transformedNode.name)) : void 0;
|
|
840
802
|
const meta = {
|
|
841
|
-
name: resolver.
|
|
803
|
+
name: resolver.resolveSchemaName(transformedNode.name),
|
|
842
804
|
file: resolver.resolveFile({
|
|
843
805
|
name: transformedNode.name,
|
|
844
806
|
extname: ".ts"
|
|
@@ -848,6 +810,21 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
848
810
|
group
|
|
849
811
|
})
|
|
850
812
|
};
|
|
813
|
+
const inferTypeName = inferred ? resolver.resolveSchemaTypeName(transformedNode.name) : void 0;
|
|
814
|
+
const schemaPrinter = mini ? printerZodMini({
|
|
815
|
+
guidType,
|
|
816
|
+
wrapOutput,
|
|
817
|
+
resolver,
|
|
818
|
+
schemaName: meta.name,
|
|
819
|
+
nodes: printer?.nodes
|
|
820
|
+
}) : printerZod({
|
|
821
|
+
coercion,
|
|
822
|
+
guidType,
|
|
823
|
+
wrapOutput,
|
|
824
|
+
resolver,
|
|
825
|
+
schemaName: meta.name,
|
|
826
|
+
nodes: printer?.nodes
|
|
827
|
+
});
|
|
851
828
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
852
829
|
baseName: meta.file.baseName,
|
|
853
830
|
path: meta.file.path,
|
|
@@ -871,28 +848,18 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
871
848
|
path: imp.path,
|
|
872
849
|
name: imp.name
|
|
873
850
|
}, [transformedNode.name, imp.path].join("-"))),
|
|
874
|
-
|
|
851
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
875
852
|
name: meta.name,
|
|
876
853
|
node: transformedNode,
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
inferTypeName,
|
|
880
|
-
resolver
|
|
881
|
-
}) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
882
|
-
name: meta.name,
|
|
883
|
-
node: transformedNode,
|
|
884
|
-
coercion,
|
|
885
|
-
guidType,
|
|
886
|
-
wrapOutput,
|
|
887
|
-
inferTypeName,
|
|
888
|
-
resolver
|
|
854
|
+
printer: schemaPrinter,
|
|
855
|
+
inferTypeName
|
|
889
856
|
})
|
|
890
857
|
]
|
|
891
858
|
});
|
|
892
859
|
},
|
|
893
|
-
Operation({ node, adapter, options, config, resolver }) {
|
|
894
|
-
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing,
|
|
895
|
-
const transformedNode = (0, _kubb_ast.transform)(node,
|
|
860
|
+
Operation({ node, adapter, options, config, resolver, plugin }) {
|
|
861
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options;
|
|
862
|
+
const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
|
|
896
863
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
897
864
|
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
898
865
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -909,9 +876,9 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
909
876
|
}) };
|
|
910
877
|
function renderSchemaEntry({ schema, name, keysToOmit }) {
|
|
911
878
|
if (!schema) return null;
|
|
912
|
-
const inferTypeName = inferred ? resolver.
|
|
879
|
+
const inferTypeName = inferred ? resolver.resolveTypeName(name) : void 0;
|
|
913
880
|
const imports = adapter.getImports(schema, (schemaName) => ({
|
|
914
|
-
name: resolver.
|
|
881
|
+
name: resolver.resolveSchemaName(schemaName),
|
|
915
882
|
path: resolver.resolveFile({
|
|
916
883
|
name: schemaName,
|
|
917
884
|
extname: ".ts"
|
|
@@ -921,6 +888,22 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
921
888
|
group
|
|
922
889
|
}).path
|
|
923
890
|
}));
|
|
891
|
+
const schemaPrinter = mini ? printerZodMini({
|
|
892
|
+
guidType,
|
|
893
|
+
wrapOutput,
|
|
894
|
+
resolver,
|
|
895
|
+
schemaName: name,
|
|
896
|
+
keysToOmit,
|
|
897
|
+
nodes: printer?.nodes
|
|
898
|
+
}) : printerZod({
|
|
899
|
+
coercion,
|
|
900
|
+
guidType,
|
|
901
|
+
wrapOutput,
|
|
902
|
+
resolver,
|
|
903
|
+
schemaName: name,
|
|
904
|
+
keysToOmit,
|
|
905
|
+
nodes: printer?.nodes
|
|
906
|
+
});
|
|
924
907
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
925
908
|
root: meta.file.path,
|
|
926
909
|
path: imp.path,
|
|
@@ -929,23 +912,11 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
929
912
|
name,
|
|
930
913
|
imp.path,
|
|
931
914
|
imp.name
|
|
932
|
-
].join("-"))),
|
|
933
|
-
name,
|
|
934
|
-
node: schema,
|
|
935
|
-
guidType,
|
|
936
|
-
wrapOutput,
|
|
937
|
-
inferTypeName,
|
|
938
|
-
resolver,
|
|
939
|
-
keysToOmit
|
|
940
|
-
}) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
915
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
941
916
|
name,
|
|
942
917
|
node: schema,
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
wrapOutput,
|
|
946
|
-
inferTypeName,
|
|
947
|
-
resolver,
|
|
948
|
-
keysToOmit
|
|
918
|
+
printer: schemaPrinter,
|
|
919
|
+
inferTypeName
|
|
949
920
|
})] });
|
|
950
921
|
}
|
|
951
922
|
const paramSchemas = params.map((param) => renderSchemaEntry({
|
|
@@ -989,8 +960,8 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
989
960
|
]
|
|
990
961
|
});
|
|
991
962
|
},
|
|
992
|
-
Operations({ nodes, adapter, options, config, resolver }) {
|
|
993
|
-
const { output, importPath, group, operations, paramsCasing
|
|
963
|
+
Operations({ nodes, adapter, options, config, resolver, plugin }) {
|
|
964
|
+
const { output, importPath, group, operations, paramsCasing } = options;
|
|
994
965
|
if (!operations) return;
|
|
995
966
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
996
967
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -1003,7 +974,7 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1003
974
|
group
|
|
1004
975
|
}) };
|
|
1005
976
|
const transformedOperations = nodes.map((node) => {
|
|
1006
|
-
const transformedNode = (0, _kubb_ast.transform)(node,
|
|
977
|
+
const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
|
|
1007
978
|
return {
|
|
1008
979
|
node: transformedNode,
|
|
1009
980
|
data: buildSchemaNames(transformedNode, {
|
|
@@ -1203,15 +1174,15 @@ function buildLegacySchemaNames(node, params, resolver) {
|
|
|
1203
1174
|
const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
1204
1175
|
name: "zod-legacy",
|
|
1205
1176
|
type: "react",
|
|
1206
|
-
Schema({ node, adapter, options, config, resolver }) {
|
|
1207
|
-
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group,
|
|
1208
|
-
const transformedNode = (0, _kubb_ast.transform)(node,
|
|
1177
|
+
Schema({ node, adapter, options, config, resolver, plugin }) {
|
|
1178
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = options;
|
|
1179
|
+
const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
|
|
1209
1180
|
if (!transformedNode.name) return;
|
|
1210
1181
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
1211
1182
|
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
1212
1183
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
1213
1184
|
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
1214
|
-
name: resolver.
|
|
1185
|
+
name: resolver.resolveSchemaName(schemaName),
|
|
1215
1186
|
path: resolver.resolveFile({
|
|
1216
1187
|
name: schemaName,
|
|
1217
1188
|
extname: ".ts"
|
|
@@ -1221,9 +1192,9 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1221
1192
|
group
|
|
1222
1193
|
}).path
|
|
1223
1194
|
}));
|
|
1224
|
-
const inferTypeName = inferred ? resolver.
|
|
1195
|
+
const inferTypeName = inferred ? resolver.resolveSchemaTypeName(transformedNode.name) : void 0;
|
|
1225
1196
|
const meta = {
|
|
1226
|
-
name: resolver.
|
|
1197
|
+
name: resolver.resolveSchemaName(transformedNode.name),
|
|
1227
1198
|
file: resolver.resolveFile({
|
|
1228
1199
|
name: transformedNode.name,
|
|
1229
1200
|
extname: ".ts"
|
|
@@ -1233,6 +1204,20 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1233
1204
|
group
|
|
1234
1205
|
})
|
|
1235
1206
|
};
|
|
1207
|
+
const schemaPrinter = mini ? printerZodMini({
|
|
1208
|
+
guidType,
|
|
1209
|
+
wrapOutput,
|
|
1210
|
+
resolver,
|
|
1211
|
+
schemaName: meta.name,
|
|
1212
|
+
nodes: printer?.nodes
|
|
1213
|
+
}) : printerZod({
|
|
1214
|
+
coercion,
|
|
1215
|
+
guidType,
|
|
1216
|
+
wrapOutput,
|
|
1217
|
+
resolver,
|
|
1218
|
+
schemaName: meta.name,
|
|
1219
|
+
nodes: printer?.nodes
|
|
1220
|
+
});
|
|
1236
1221
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
1237
1222
|
baseName: meta.file.baseName,
|
|
1238
1223
|
path: meta.file.path,
|
|
@@ -1256,28 +1241,18 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1256
1241
|
path: imp.path,
|
|
1257
1242
|
name: imp.name
|
|
1258
1243
|
}, [transformedNode.name, imp.path].join("-"))),
|
|
1259
|
-
|
|
1244
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
1260
1245
|
name: meta.name,
|
|
1261
1246
|
node: transformedNode,
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
inferTypeName,
|
|
1265
|
-
resolver
|
|
1266
|
-
}) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
1267
|
-
name: meta.name,
|
|
1268
|
-
node: transformedNode,
|
|
1269
|
-
coercion,
|
|
1270
|
-
guidType,
|
|
1271
|
-
wrapOutput,
|
|
1272
|
-
inferTypeName,
|
|
1273
|
-
resolver
|
|
1247
|
+
printer: schemaPrinter,
|
|
1248
|
+
inferTypeName
|
|
1274
1249
|
})
|
|
1275
1250
|
]
|
|
1276
1251
|
});
|
|
1277
1252
|
},
|
|
1278
|
-
Operation({ node, adapter, options, config, resolver }) {
|
|
1279
|
-
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing,
|
|
1280
|
-
const transformedNode = (0, _kubb_ast.transform)(node,
|
|
1253
|
+
Operation({ node, adapter, options, config, resolver, plugin }) {
|
|
1254
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options;
|
|
1255
|
+
const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
|
|
1281
1256
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
1282
1257
|
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
1283
1258
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -1294,9 +1269,9 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1294
1269
|
}) };
|
|
1295
1270
|
function renderSchemaEntry({ schema, name, keysToOmit }) {
|
|
1296
1271
|
if (!schema) return null;
|
|
1297
|
-
const inferTypeName = inferred ? resolver.
|
|
1272
|
+
const inferTypeName = inferred ? resolver.resolveTypeName(name) : void 0;
|
|
1298
1273
|
const imports = adapter.getImports(schema, (schemaName) => ({
|
|
1299
|
-
name: resolver.
|
|
1274
|
+
name: resolver.resolveSchemaName(schemaName),
|
|
1300
1275
|
path: resolver.resolveFile({
|
|
1301
1276
|
name: schemaName,
|
|
1302
1277
|
extname: ".ts"
|
|
@@ -1306,6 +1281,22 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1306
1281
|
group
|
|
1307
1282
|
}).path
|
|
1308
1283
|
}));
|
|
1284
|
+
const schemaPrinter = mini ? printerZodMini({
|
|
1285
|
+
guidType,
|
|
1286
|
+
wrapOutput,
|
|
1287
|
+
resolver,
|
|
1288
|
+
schemaName: name,
|
|
1289
|
+
keysToOmit,
|
|
1290
|
+
nodes: printer?.nodes
|
|
1291
|
+
}) : printerZod({
|
|
1292
|
+
coercion,
|
|
1293
|
+
guidType,
|
|
1294
|
+
wrapOutput,
|
|
1295
|
+
resolver,
|
|
1296
|
+
schemaName: name,
|
|
1297
|
+
keysToOmit,
|
|
1298
|
+
nodes: printer?.nodes
|
|
1299
|
+
});
|
|
1309
1300
|
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
1310
1301
|
root: meta.file.path,
|
|
1311
1302
|
path: imp.path,
|
|
@@ -1314,23 +1305,11 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1314
1305
|
name,
|
|
1315
1306
|
imp.path,
|
|
1316
1307
|
imp.name
|
|
1317
|
-
].join("-"))),
|
|
1308
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
1318
1309
|
name,
|
|
1319
1310
|
node: schema,
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
inferTypeName,
|
|
1323
|
-
resolver,
|
|
1324
|
-
keysToOmit
|
|
1325
|
-
}) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Zod, {
|
|
1326
|
-
name,
|
|
1327
|
-
node: schema,
|
|
1328
|
-
coercion,
|
|
1329
|
-
guidType,
|
|
1330
|
-
wrapOutput,
|
|
1331
|
-
inferTypeName,
|
|
1332
|
-
resolver,
|
|
1333
|
-
keysToOmit
|
|
1311
|
+
printer: schemaPrinter,
|
|
1312
|
+
inferTypeName
|
|
1334
1313
|
})] });
|
|
1335
1314
|
}
|
|
1336
1315
|
const pathParams = params.filter((p) => p.in === "path");
|
|
@@ -1412,8 +1391,8 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1412
1391
|
]
|
|
1413
1392
|
});
|
|
1414
1393
|
},
|
|
1415
|
-
Operations({ nodes, adapter, options, config, resolver }) {
|
|
1416
|
-
const { output, importPath, group, operations, paramsCasing
|
|
1394
|
+
Operations({ nodes, adapter, options, config, resolver, plugin }) {
|
|
1395
|
+
const { output, importPath, group, operations, paramsCasing } = options;
|
|
1417
1396
|
if (!operations) return;
|
|
1418
1397
|
const root = node_path.default.resolve(config.root, config.output.path);
|
|
1419
1398
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -1426,7 +1405,7 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1426
1405
|
group
|
|
1427
1406
|
}) };
|
|
1428
1407
|
const transformedOperations = nodes.map((node) => {
|
|
1429
|
-
const transformedNode = (0, _kubb_ast.transform)(node,
|
|
1408
|
+
const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
|
|
1430
1409
|
return {
|
|
1431
1410
|
node: transformedNode,
|
|
1432
1411
|
data: buildLegacySchemaNames(transformedNode, (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing), resolver)
|
|
@@ -1484,14 +1463,6 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1484
1463
|
});
|
|
1485
1464
|
//#endregion
|
|
1486
1465
|
//#region src/resolvers/resolverZod.ts
|
|
1487
|
-
function toSchemaName(name, type) {
|
|
1488
|
-
const resolved = camelCase(name, {
|
|
1489
|
-
suffix: type ? "schema" : void 0,
|
|
1490
|
-
isFile: type === "file"
|
|
1491
|
-
});
|
|
1492
|
-
if (type === "type") return pascalCase(resolved);
|
|
1493
|
-
return resolved;
|
|
1494
|
-
}
|
|
1495
1466
|
/**
|
|
1496
1467
|
* Default resolver for `@kubb/plugin-zod`.
|
|
1497
1468
|
*
|
|
@@ -1509,31 +1480,37 @@ const resolverZod = (0, _kubb_core.defineResolver)(() => {
|
|
|
1509
1480
|
name: "default",
|
|
1510
1481
|
pluginName: "plugin-zod",
|
|
1511
1482
|
default(name, type) {
|
|
1512
|
-
return
|
|
1483
|
+
return camelCase(name, {
|
|
1484
|
+
isFile: type === "file",
|
|
1485
|
+
suffix: type ? "schema" : void 0
|
|
1486
|
+
});
|
|
1487
|
+
},
|
|
1488
|
+
resolveSchemaName(name) {
|
|
1489
|
+
return camelCase(name, { suffix: "schema" });
|
|
1513
1490
|
},
|
|
1514
|
-
|
|
1515
|
-
return
|
|
1491
|
+
resolveSchemaTypeName(name) {
|
|
1492
|
+
return pascalCase(name, { suffix: "schema" });
|
|
1516
1493
|
},
|
|
1517
|
-
|
|
1494
|
+
resolveTypeName(name) {
|
|
1518
1495
|
return pascalCase(name);
|
|
1519
1496
|
},
|
|
1520
1497
|
resolvePathName(name, type) {
|
|
1521
1498
|
return this.default(name, type);
|
|
1522
1499
|
},
|
|
1523
1500
|
resolveParamName(node, param) {
|
|
1524
|
-
return this.
|
|
1501
|
+
return this.resolveSchemaName(`${node.operationId} ${param.in} ${param.name}`);
|
|
1525
1502
|
},
|
|
1526
1503
|
resolveResponseStatusName(node, statusCode) {
|
|
1527
|
-
return this.
|
|
1504
|
+
return this.resolveSchemaName(`${node.operationId} Status ${statusCode}`);
|
|
1528
1505
|
},
|
|
1529
1506
|
resolveDataName(node) {
|
|
1530
|
-
return this.
|
|
1507
|
+
return this.resolveSchemaName(`${node.operationId} Data`);
|
|
1531
1508
|
},
|
|
1532
1509
|
resolveResponsesName(node) {
|
|
1533
|
-
return this.
|
|
1510
|
+
return this.resolveSchemaName(`${node.operationId} Responses`);
|
|
1534
1511
|
},
|
|
1535
1512
|
resolveResponseName(node) {
|
|
1536
|
-
return this.
|
|
1513
|
+
return this.resolveSchemaName(`${node.operationId} Response`);
|
|
1537
1514
|
},
|
|
1538
1515
|
resolvePathParamsName(node, param) {
|
|
1539
1516
|
return this.resolveParamName(node, param);
|
|
@@ -1576,29 +1553,29 @@ const resolverZodLegacy = (0, _kubb_core.defineResolver)(() => {
|
|
|
1576
1553
|
...resolverZod,
|
|
1577
1554
|
pluginName: "plugin-zod",
|
|
1578
1555
|
resolveResponseStatusName(node, statusCode) {
|
|
1579
|
-
if (statusCode === "default") return this.
|
|
1580
|
-
return this.
|
|
1556
|
+
if (statusCode === "default") return this.resolveSchemaName(`${node.operationId} Error`);
|
|
1557
|
+
return this.resolveSchemaName(`${node.operationId} ${statusCode}`);
|
|
1581
1558
|
},
|
|
1582
1559
|
resolveDataName(node) {
|
|
1583
1560
|
const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
|
|
1584
|
-
return this.
|
|
1561
|
+
return this.resolveSchemaName(`${node.operationId} ${suffix}`);
|
|
1585
1562
|
},
|
|
1586
1563
|
resolveResponsesName(node) {
|
|
1587
1564
|
const suffix = node.method === "GET" ? "Query" : "Mutation";
|
|
1588
|
-
return this.
|
|
1565
|
+
return this.resolveSchemaName(`${node.operationId} ${suffix}`);
|
|
1589
1566
|
},
|
|
1590
1567
|
resolveResponseName(node) {
|
|
1591
1568
|
const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
|
|
1592
|
-
return this.
|
|
1569
|
+
return this.resolveSchemaName(`${node.operationId} ${suffix}`);
|
|
1593
1570
|
},
|
|
1594
1571
|
resolvePathParamsName(node, _param) {
|
|
1595
|
-
return this.
|
|
1572
|
+
return this.resolveSchemaName(`${node.operationId} PathParams`);
|
|
1596
1573
|
},
|
|
1597
1574
|
resolveQueryParamsName(node, _param) {
|
|
1598
|
-
return this.
|
|
1575
|
+
return this.resolveSchemaName(`${node.operationId} QueryParams`);
|
|
1599
1576
|
},
|
|
1600
1577
|
resolveHeaderParamsName(node, _param) {
|
|
1601
|
-
return this.
|
|
1578
|
+
return this.resolveSchemaName(`${node.operationId} HeaderParams`);
|
|
1602
1579
|
}
|
|
1603
1580
|
};
|
|
1604
1581
|
});
|
|
@@ -1609,17 +1586,21 @@ const resolverZodLegacy = (0, _kubb_core.defineResolver)(() => {
|
|
|
1609
1586
|
*
|
|
1610
1587
|
* - `default` — uses `resolverZod` and `zodGenerator` (current naming conventions).
|
|
1611
1588
|
* - `kubbV4` — uses `resolverZodLegacy` and `zodGeneratorLegacy` (Kubb v4 naming conventions).
|
|
1589
|
+
*
|
|
1590
|
+
* Note: `printerZodMini` is selected at runtime by the generator when `mini: true` is set.
|
|
1612
1591
|
*/
|
|
1613
1592
|
const presets = (0, _kubb_core.definePresets)({
|
|
1614
1593
|
default: {
|
|
1615
1594
|
name: "default",
|
|
1616
|
-
|
|
1617
|
-
generators: [zodGenerator]
|
|
1595
|
+
resolver: resolverZod,
|
|
1596
|
+
generators: [zodGenerator],
|
|
1597
|
+
printer: printerZod
|
|
1618
1598
|
},
|
|
1619
1599
|
kubbV4: {
|
|
1620
1600
|
name: "kubbV4",
|
|
1621
|
-
|
|
1622
|
-
generators: [zodGeneratorLegacy]
|
|
1601
|
+
resolver: resolverZodLegacy,
|
|
1602
|
+
generators: [zodGeneratorLegacy],
|
|
1603
|
+
printer: printerZod
|
|
1623
1604
|
}
|
|
1624
1605
|
});
|
|
1625
1606
|
//#endregion
|
|
@@ -1648,12 +1629,12 @@ const pluginZod = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1648
1629
|
const { output = {
|
|
1649
1630
|
path: "zod",
|
|
1650
1631
|
barrelType: "named"
|
|
1651
|
-
}, group, exclude = [], include, override = [], dateType = "string", typed = false, operations = false, mini = false, guidType = "uuid", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, paramsCasing, compatibilityPreset = "default",
|
|
1632
|
+
}, group, exclude = [], include, override = [], dateType = "string", typed = false, operations = false, mini = false, guidType = "uuid", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, paramsCasing, printer, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
|
|
1652
1633
|
const preset = (0, _kubb_core.getPreset)({
|
|
1653
1634
|
preset: compatibilityPreset,
|
|
1654
1635
|
presets,
|
|
1655
|
-
|
|
1656
|
-
|
|
1636
|
+
resolver: userResolver,
|
|
1637
|
+
transformer: userTransformer,
|
|
1657
1638
|
generators: userGenerators
|
|
1658
1639
|
});
|
|
1659
1640
|
let resolveNameWarning = false;
|
|
@@ -1663,6 +1644,9 @@ const pluginZod = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1663
1644
|
get resolver() {
|
|
1664
1645
|
return preset.resolver;
|
|
1665
1646
|
},
|
|
1647
|
+
get transformer() {
|
|
1648
|
+
return preset.transformer;
|
|
1649
|
+
},
|
|
1666
1650
|
get options() {
|
|
1667
1651
|
return {
|
|
1668
1652
|
output,
|
|
@@ -1683,7 +1667,7 @@ const pluginZod = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1683
1667
|
mini,
|
|
1684
1668
|
wrapOutput,
|
|
1685
1669
|
paramsCasing,
|
|
1686
|
-
|
|
1670
|
+
printer
|
|
1687
1671
|
};
|
|
1688
1672
|
},
|
|
1689
1673
|
resolvePath(baseName, pathMode, options) {
|