@kubb/plugin-zod 3.0.0-alpha.7 → 3.0.0-alpha.9
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/{chunk-PXJ5ZGKW.cjs → chunk-57AHBVYK.cjs} +65 -58
- package/dist/chunk-57AHBVYK.cjs.map +1 -0
- package/dist/{chunk-VSAW3SUC.js → chunk-CUPQVLRZ.js} +77 -70
- package/dist/chunk-CUPQVLRZ.js.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +1 -1
- package/package.json +12 -12
- package/src/SchemaGenerator.tsx +4 -4
- package/src/components/Operations.tsx +4 -4
- package/src/components/Schema.tsx +3 -3
- package/src/parser/index.ts +10 -2
- package/dist/chunk-PXJ5ZGKW.cjs.map +0 -1
- package/dist/chunk-VSAW3SUC.js.map +0 -1
|
@@ -2225,9 +2225,9 @@ import { File, Type, useApp } from "@kubb/react";
|
|
|
2225
2225
|
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
2226
2226
|
function Template({ name, typeName, api }) {
|
|
2227
2227
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2228
|
-
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2228
|
+
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2229
2229
|
/* @__PURE__ */ jsx("br", {}),
|
|
2230
|
-
/* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2230
|
+
/* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2231
2231
|
] });
|
|
2232
2232
|
}
|
|
2233
2233
|
var defaultTemplates = { default: Template };
|
|
@@ -2565,10 +2565,10 @@ function Schema(props) {
|
|
|
2565
2565
|
);
|
|
2566
2566
|
return /* @__PURE__ */ jsxs2(import_react3.Fragment, { children: [
|
|
2567
2567
|
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */ jsxs2(import_react3.Fragment, { children: [
|
|
2568
|
-
nameNode && /* @__PURE__ */ jsx2(File2.Source, { name: name2, isExportable: true, children: print(nameNode) }),
|
|
2569
|
-
/* @__PURE__ */ jsx2(File2.Source, { name: typeName2, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: print(typeNode) })
|
|
2568
|
+
nameNode && /* @__PURE__ */ jsx2(File2.Source, { name: name2, isExportable: true, isIndexable: true, children: print(nameNode) }),
|
|
2569
|
+
/* @__PURE__ */ jsx2(File2.Source, { name: typeName2, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: print(typeNode) })
|
|
2570
2570
|
] }, [name2, nameNode].join("-"))),
|
|
2571
|
-
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ jsx2(File2.Source, { name: typeName, isTypeOnly: true, isExportable: true, children: print(typeNodes) })
|
|
2571
|
+
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ jsx2(File2.Source, { name: typeName, isTypeOnly: true, isExportable: true, isIndexable: true, children: print(typeNodes) })
|
|
2572
2572
|
] });
|
|
2573
2573
|
}
|
|
2574
2574
|
Schema.File = function({}) {
|
|
@@ -2701,7 +2701,7 @@ OperationSchema.File = function({}) {
|
|
|
2701
2701
|
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2702
2702
|
return /* @__PURE__ */ jsxs3(File3, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2703
2703
|
items.map(mapItem),
|
|
2704
|
-
/* @__PURE__ */ jsx4(File3.Source, { name: combinedSchemaName, isExportable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2704
|
+
/* @__PURE__ */ jsx4(File3.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2705
2705
|
] });
|
|
2706
2706
|
};
|
|
2707
2707
|
|
|
@@ -2850,7 +2850,11 @@ var zodKeywordMapper = {
|
|
|
2850
2850
|
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
2851
2851
|
},
|
|
2852
2852
|
integer: (coercion, min, max) => {
|
|
2853
|
-
return [
|
|
2853
|
+
return [
|
|
2854
|
+
coercion ? "z.coerce.number().int()" : "z.number().int()",
|
|
2855
|
+
min !== void 0 ? `.min(${min})` : void 0,
|
|
2856
|
+
max !== void 0 ? `.max(${max})` : void 0
|
|
2857
|
+
].filter(Boolean).join("");
|
|
2854
2858
|
},
|
|
2855
2859
|
object: (value) => `z.object({${value}})`,
|
|
2856
2860
|
string: (coercion, min, max) => {
|
|
@@ -3070,9 +3074,12 @@ function parse2(parent, current, options) {
|
|
|
3070
3074
|
if (isKeyword2(current, schemaKeywords3.string)) {
|
|
3071
3075
|
return zodKeywordMapper.string(options.coercion);
|
|
3072
3076
|
}
|
|
3073
|
-
if (isKeyword2(current, schemaKeywords3.number)
|
|
3077
|
+
if (isKeyword2(current, schemaKeywords3.number)) {
|
|
3074
3078
|
return zodKeywordMapper.number(options.coercion);
|
|
3075
3079
|
}
|
|
3080
|
+
if (isKeyword2(current, schemaKeywords3.integer)) {
|
|
3081
|
+
return zodKeywordMapper.integer(options.coercion);
|
|
3082
|
+
}
|
|
3076
3083
|
if (isKeyword2(current, schemaKeywords3.min)) {
|
|
3077
3084
|
return zodKeywordMapper.min(current.args);
|
|
3078
3085
|
}
|
|
@@ -3108,16 +3115,56 @@ import { OperationGenerator as OperationGenerator2, SchemaGenerator as SchemaGen
|
|
|
3108
3115
|
|
|
3109
3116
|
// src/SchemaGenerator.tsx
|
|
3110
3117
|
init_esm_shims();
|
|
3111
|
-
import {
|
|
3118
|
+
import { createReactGenerator } from "@kubb/plugin-oas";
|
|
3119
|
+
|
|
3120
|
+
// src/components/OperationSchema.tsx
|
|
3121
|
+
init_esm_shims();
|
|
3122
|
+
import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
3123
|
+
import { Oas as Oas5 } from "@kubb/plugin-oas/components";
|
|
3124
|
+
import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
|
|
3125
|
+
import { File as File4, useApp as useApp4 } from "@kubb/react";
|
|
3126
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
|
|
3127
|
+
function OperationSchema2({ description, keysToOmit }) {
|
|
3128
|
+
return /* @__PURE__ */ jsx6(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3129
|
+
}
|
|
3130
|
+
OperationSchema2.File = function({}) {
|
|
3131
|
+
const { pluginManager, plugin, mode } = useApp4();
|
|
3132
|
+
const { getSchemas, getFile } = useOperationManager2();
|
|
3133
|
+
const oas = useOas3();
|
|
3134
|
+
const operation = useOperation2();
|
|
3135
|
+
const file = getFile(operation);
|
|
3136
|
+
const schemas = getSchemas(operation);
|
|
3137
|
+
const generator = new SchemaGenerator3(plugin.options, {
|
|
3138
|
+
oas,
|
|
3139
|
+
plugin,
|
|
3140
|
+
pluginManager,
|
|
3141
|
+
mode,
|
|
3142
|
+
override: plugin.options.override
|
|
3143
|
+
});
|
|
3144
|
+
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
3145
|
+
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
3146
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
3147
|
+
const optional = !required && !!name.includes("Params");
|
|
3148
|
+
const tree = generator.parse({ schema, name });
|
|
3149
|
+
return /* @__PURE__ */ jsxs4(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
|
|
3150
|
+
mode === "split" && /* @__PURE__ */ jsx6(Oas5.Schema.Imports, { isTypeOnly: false }),
|
|
3151
|
+
/* @__PURE__ */ jsx6(OperationSchema2, { description, keysToOmit })
|
|
3152
|
+
] }, i);
|
|
3153
|
+
};
|
|
3154
|
+
return /* @__PURE__ */ jsxs4(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3155
|
+
/* @__PURE__ */ jsx6(File4.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
3156
|
+
items.map(mapItem)
|
|
3157
|
+
] });
|
|
3158
|
+
};
|
|
3112
3159
|
|
|
3113
3160
|
// src/components/Operations.tsx
|
|
3114
3161
|
init_esm_shims();
|
|
3115
|
-
import { useOperationManager as
|
|
3116
|
-
import { Const, File as
|
|
3162
|
+
import { useOperationManager as useOperationManager3, useOperations } from "@kubb/plugin-oas/hooks";
|
|
3163
|
+
import { Const, File as File5, useApp as useApp5 } from "@kubb/react";
|
|
3117
3164
|
import transformers5 from "@kubb/core/transformers";
|
|
3118
|
-
import { Fragment as Fragment3, jsx as
|
|
3165
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
|
|
3119
3166
|
function Template2({ operationsName, pathsName, operations }) {
|
|
3120
|
-
const { groupSchemasByName } =
|
|
3167
|
+
const { groupSchemasByName } = useOperationManager3();
|
|
3121
3168
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3122
3169
|
const operationsJSON = transformedOperations.reduce(
|
|
3123
3170
|
(prev, acc) => {
|
|
@@ -3136,9 +3183,9 @@ function Template2({ operationsName, pathsName, operations }) {
|
|
|
3136
3183
|
},
|
|
3137
3184
|
{}
|
|
3138
3185
|
);
|
|
3139
|
-
return /* @__PURE__ */
|
|
3140
|
-
/* @__PURE__ */
|
|
3141
|
-
/* @__PURE__ */
|
|
3186
|
+
return /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
3187
|
+
/* @__PURE__ */ jsx7(File5.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx7(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers5.stringifyObject(operationsJSON)}}` }) }),
|
|
3188
|
+
/* @__PURE__ */ jsx7(File5.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx7(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers5.stringifyObject(pathsJSON)}}` }) })
|
|
3142
3189
|
] });
|
|
3143
3190
|
}
|
|
3144
3191
|
function RootTemplate({ children }) {
|
|
@@ -3149,17 +3196,17 @@ function RootTemplate({ children }) {
|
|
|
3149
3196
|
key: pluginKey,
|
|
3150
3197
|
options: { extName }
|
|
3151
3198
|
}
|
|
3152
|
-
} =
|
|
3153
|
-
const { getFile } =
|
|
3199
|
+
} = useApp5();
|
|
3200
|
+
const { getFile } = useOperationManager3();
|
|
3154
3201
|
const operations = useOperations();
|
|
3155
|
-
const { groupSchemasByName } =
|
|
3202
|
+
const { groupSchemasByName } = useOperationManager3();
|
|
3156
3203
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3157
3204
|
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
3158
|
-
const imports = Object.entries(transformedOperations).map(([
|
|
3205
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
3159
3206
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
3160
|
-
return /* @__PURE__ */
|
|
3207
|
+
return /* @__PURE__ */ jsx7(File5.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
3161
3208
|
}).filter(Boolean);
|
|
3162
|
-
return /* @__PURE__ */
|
|
3209
|
+
return /* @__PURE__ */ jsxs5(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3163
3210
|
mode === "split" && imports,
|
|
3164
3211
|
children
|
|
3165
3212
|
] });
|
|
@@ -3167,59 +3214,19 @@ function RootTemplate({ children }) {
|
|
|
3167
3214
|
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
3168
3215
|
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
3169
3216
|
const operations = useOperations();
|
|
3170
|
-
return /* @__PURE__ */
|
|
3217
|
+
return /* @__PURE__ */ jsx7(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
3171
3218
|
}
|
|
3172
3219
|
Operations.File = function(props) {
|
|
3173
3220
|
const templates = { ...defaultTemplates2, ...props.templates };
|
|
3174
3221
|
const Template3 = templates.default;
|
|
3175
3222
|
const RootTemplate2 = templates.root;
|
|
3176
|
-
return /* @__PURE__ */
|
|
3223
|
+
return /* @__PURE__ */ jsx7(RootTemplate2, { children: /* @__PURE__ */ jsx7(Operations, { Template: Template3 }) });
|
|
3177
3224
|
};
|
|
3178
3225
|
Operations.templates = defaultTemplates2;
|
|
3179
3226
|
|
|
3180
|
-
// src/components/OperationSchema.tsx
|
|
3181
|
-
init_esm_shims();
|
|
3182
|
-
import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
3183
|
-
import { Oas as Oas5 } from "@kubb/plugin-oas/components";
|
|
3184
|
-
import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
|
|
3185
|
-
import { File as File5, useApp as useApp5 } from "@kubb/react";
|
|
3186
|
-
import { jsx as jsx7, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
|
|
3187
|
-
function OperationSchema2({ description, keysToOmit }) {
|
|
3188
|
-
return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3189
|
-
}
|
|
3190
|
-
OperationSchema2.File = function({}) {
|
|
3191
|
-
const { pluginManager, plugin, mode } = useApp5();
|
|
3192
|
-
const { getSchemas, getFile } = useOperationManager3();
|
|
3193
|
-
const oas = useOas3();
|
|
3194
|
-
const operation = useOperation2();
|
|
3195
|
-
const file = getFile(operation);
|
|
3196
|
-
const schemas = getSchemas(operation);
|
|
3197
|
-
const generator = new SchemaGenerator3(plugin.options, {
|
|
3198
|
-
oas,
|
|
3199
|
-
plugin,
|
|
3200
|
-
pluginManager,
|
|
3201
|
-
mode,
|
|
3202
|
-
override: plugin.options.override
|
|
3203
|
-
});
|
|
3204
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
3205
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
3206
|
-
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
3207
|
-
const optional = !required && !!name.includes("Params");
|
|
3208
|
-
const tree = generator.parse({ schema, name });
|
|
3209
|
-
return /* @__PURE__ */ jsxs5(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
|
|
3210
|
-
mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { isTypeOnly: false }),
|
|
3211
|
-
/* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit })
|
|
3212
|
-
] }, i);
|
|
3213
|
-
};
|
|
3214
|
-
return /* @__PURE__ */ jsxs5(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3215
|
-
/* @__PURE__ */ jsx7(File5.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
3216
|
-
items.map(mapItem)
|
|
3217
|
-
] });
|
|
3218
|
-
};
|
|
3219
|
-
|
|
3220
3227
|
// src/SchemaGenerator.tsx
|
|
3221
3228
|
import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
|
|
3222
|
-
var zodParser =
|
|
3229
|
+
var zodParser = createReactGenerator({
|
|
3223
3230
|
name: "plugin-zod",
|
|
3224
3231
|
Operations({ options }) {
|
|
3225
3232
|
if (!options.templates.operations) {
|
|
@@ -3377,7 +3384,7 @@ function Schema2(props) {
|
|
|
3377
3384
|
type: "type"
|
|
3378
3385
|
});
|
|
3379
3386
|
if (!tree.length) {
|
|
3380
|
-
return /* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, children: /* @__PURE__ */ jsx9(
|
|
3387
|
+
return /* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx9(
|
|
3381
3388
|
Const2,
|
|
3382
3389
|
{
|
|
3383
3390
|
name: resolvedName,
|
|
@@ -3398,7 +3405,7 @@ function Schema2(props) {
|
|
|
3398
3405
|
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
3399
3406
|
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
3400
3407
|
return /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
|
3401
|
-
/* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, children: /* @__PURE__ */ jsx9(
|
|
3408
|
+
/* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx9(
|
|
3402
3409
|
Const2,
|
|
3403
3410
|
{
|
|
3404
3411
|
export: true,
|
|
@@ -3413,7 +3420,7 @@ function Schema2(props) {
|
|
|
3413
3420
|
].filter(Boolean).join("") || ""
|
|
3414
3421
|
}
|
|
3415
3422
|
) }),
|
|
3416
|
-
typedSchema && /* @__PURE__ */ jsx9(File6.Source, { name: resolvedTypeName, isExportable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3423
|
+
typedSchema && /* @__PURE__ */ jsx9(File6.Source, { name: resolvedTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3417
3424
|
] });
|
|
3418
3425
|
}
|
|
3419
3426
|
Schema2.File = function({}) {
|
|
@@ -3463,8 +3470,8 @@ Schema2.Imports = () => {
|
|
|
3463
3470
|
export {
|
|
3464
3471
|
init_esm_shims,
|
|
3465
3472
|
Schema2 as Schema,
|
|
3466
|
-
Operations,
|
|
3467
3473
|
OperationSchema2 as OperationSchema,
|
|
3474
|
+
Operations,
|
|
3468
3475
|
pluginZodName,
|
|
3469
3476
|
pluginZod
|
|
3470
3477
|
};
|
|
@@ -3492,4 +3499,4 @@ react/cjs/react.development.js:
|
|
|
3492
3499
|
* LICENSE file in the root directory of this source tree.
|
|
3493
3500
|
*)
|
|
3494
3501
|
*/
|
|
3495
|
-
//# sourceMappingURL=chunk-
|
|
3502
|
+
//# sourceMappingURL=chunk-CUPQVLRZ.js.map
|