@kubb/plugin-zod 3.0.0-alpha.2 → 3.0.0-alpha.21
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/README.md +13 -4
- package/dist/chunk-GILKYHDS.cjs +250 -0
- package/dist/chunk-GILKYHDS.cjs.map +1 -0
- package/dist/chunk-KGKZCQKF.js +322 -0
- package/dist/chunk-KGKZCQKF.js.map +1 -0
- package/dist/chunk-RPZWETTK.cjs +329 -0
- package/dist/chunk-RPZWETTK.cjs.map +1 -0
- package/dist/chunk-WIOP5MTW.js +241 -0
- package/dist/chunk-WIOP5MTW.js.map +1 -0
- package/dist/components.cjs +11 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +20 -19
- package/dist/components.d.ts +20 -19
- package/dist/components.js +2 -10
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -137
- package/dist/index.d.ts +4 -137
- package/dist/index.js +3 -8
- package/dist/index.js.map +1 -1
- package/dist/types-BRWHhUnI.d.cts +109 -0
- package/dist/types-BRWHhUnI.d.ts +109 -0
- package/package.json +19 -21
- package/src/components/Operations.tsx +19 -103
- package/src/components/Zod.tsx +66 -0
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/anyof.ts +3 -0
- package/src/generators/__snapshots__/createPet.ts +15 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/enumNamesType.ts +3 -0
- package/src/generators/__snapshots__/enumNullable.ts +3 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +3 -0
- package/src/generators/__snapshots__/example.ts +3 -0
- package/src/generators/__snapshots__/getPets.ts +18 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -0
- package/src/generators/__snapshots__/nullableString.ts +3 -0
- package/src/generators/__snapshots__/nullableStringUuid.ts +3 -0
- package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +3 -0
- package/src/generators/__snapshots__/numberValueConst.ts +6 -0
- package/src/generators/__snapshots__/oneof.ts +3 -0
- package/src/generators/__snapshots__/operations.ts +46 -0
- package/src/generators/__snapshots__/optionalPetInfer.ts +5 -0
- package/src/generators/__snapshots__/optionalPetTyped.ts +3 -0
- package/src/generators/__snapshots__/order.ts +3 -0
- package/src/generators/__snapshots__/orderDateTyeString.ts +10 -0
- package/src/generators/__snapshots__/orderDateTypeFalse.ts +3 -0
- package/src/generators/__snapshots__/orderDateTypeString.ts +3 -0
- package/src/generators/__snapshots__/pet.ts +3 -0
- package/src/generators/__snapshots__/petArray.ts +6 -0
- package/src/generators/__snapshots__/petCoercion.ts +3 -0
- package/src/generators/__snapshots__/petTupleObject.ts +6 -0
- package/src/generators/__snapshots__/petWithMapper.ts +3 -0
- package/src/generators/__snapshots__/pets.ts +3 -0
- package/src/generators/__snapshots__/recursive.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +18 -0
- package/src/generators/__snapshots__/stringValueConst.ts +6 -0
- package/src/generators/__snapshots__/uuidSchema.ts +3 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/operationsGenerator.tsx +39 -0
- package/src/generators/zodGenerator.tsx +121 -0
- package/src/parser/index.ts +11 -3
- package/src/plugin.ts +22 -37
- package/src/types.ts +38 -70
- package/dist/Operations-BlQtRP31.d.cts +0 -47
- package/dist/Operations-BlQtRP31.d.ts +0 -47
- package/dist/chunk-KP7GRUCO.cjs +0 -1279
- package/dist/chunk-KP7GRUCO.cjs.map +0 -1
- package/dist/chunk-ORHAR2XI.js +0 -1279
- package/dist/chunk-ORHAR2XI.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -54
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -66
- package/src/components/Schema.tsx +0 -171
- package/src/components/__snapshots__/operations.ts +0 -50
package/README.md
CHANGED
|
@@ -13,10 +13,6 @@
|
|
|
13
13
|
[![Coverage][coverage-src]][coverage-href]
|
|
14
14
|
[![License][license-src]][license-href]
|
|
15
15
|
|
|
16
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
16
|
<h4>
|
|
21
17
|
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
|
|
22
18
|
<span> · </span>
|
|
@@ -28,6 +24,19 @@
|
|
|
28
24
|
</h4>
|
|
29
25
|
</div>
|
|
30
26
|
|
|
27
|
+
## Supporting Kubb
|
|
28
|
+
|
|
29
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
30
|
+
|
|
31
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
|
|
31
40
|
<!-- Badges -->
|
|
32
41
|
|
|
33
42
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-zod?flat&colorA=18181B&colorB=f58517
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkRPZWETTK_cjs = require('./chunk-RPZWETTK.cjs');
|
|
4
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
5
|
+
var components = require('@kubb/plugin-oas/components');
|
|
6
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
7
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
8
|
+
var react = require('@kubb/react');
|
|
9
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
10
|
+
var path = require('path');
|
|
11
|
+
var core = require('@kubb/core');
|
|
12
|
+
var transformers = require('@kubb/core/transformers');
|
|
13
|
+
var utils = require('@kubb/core/utils');
|
|
14
|
+
|
|
15
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
|
|
17
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
18
|
+
|
|
19
|
+
var zodGenerator = pluginOas.createReactGenerator({
|
|
20
|
+
name: "zod",
|
|
21
|
+
Operation({ operation, options }) {
|
|
22
|
+
const { coercion, inferred, typed, mapper } = options;
|
|
23
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
24
|
+
const oas = hooks.useOas();
|
|
25
|
+
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
26
|
+
const schemaManager = hooks.useSchemaManager();
|
|
27
|
+
const file = getFile(operation);
|
|
28
|
+
const schemas = getSchemas(operation);
|
|
29
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(options, {
|
|
30
|
+
oas,
|
|
31
|
+
plugin,
|
|
32
|
+
pluginManager,
|
|
33
|
+
mode,
|
|
34
|
+
override: options.override
|
|
35
|
+
});
|
|
36
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
37
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
38
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
39
|
+
const optional = !required && !!name.includes("Params");
|
|
40
|
+
const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean);
|
|
41
|
+
const imports = schemaManager.getImports(tree);
|
|
42
|
+
const zod = {
|
|
43
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
44
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
45
|
+
file: schemaManager.getFile(name)
|
|
46
|
+
};
|
|
47
|
+
const type = {
|
|
48
|
+
name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
|
|
49
|
+
file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTs.pluginTsName], tag: options2.operation?.getTags()[0]?.name })
|
|
50
|
+
};
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
52
|
+
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
53
|
+
imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
+
chunkRPZWETTK_cjs.Zod,
|
|
56
|
+
{
|
|
57
|
+
name: zod.name,
|
|
58
|
+
typeName: typed ? type.name : void 0,
|
|
59
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
60
|
+
description,
|
|
61
|
+
tree,
|
|
62
|
+
mapper,
|
|
63
|
+
coercion,
|
|
64
|
+
keysToOmit
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
] }, i);
|
|
68
|
+
};
|
|
69
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
71
|
+
operationSchemas.map(mapOperationSchema)
|
|
72
|
+
] });
|
|
73
|
+
},
|
|
74
|
+
Schema({ schema, options }) {
|
|
75
|
+
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
76
|
+
const { getName, getFile, getImports } = hooks.useSchemaManager();
|
|
77
|
+
const {
|
|
78
|
+
plugin: {
|
|
79
|
+
options: { output }
|
|
80
|
+
}
|
|
81
|
+
} = react.useApp();
|
|
82
|
+
const imports = getImports(schema.tree);
|
|
83
|
+
const zod = {
|
|
84
|
+
name: getName(schema.name, { type: "function" }),
|
|
85
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
86
|
+
file: getFile(schema.name)
|
|
87
|
+
};
|
|
88
|
+
const type = {
|
|
89
|
+
name: getName(schema.name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
|
|
90
|
+
file: getFile(schema.name, { pluginKey: [pluginTs.pluginTsName] })
|
|
91
|
+
};
|
|
92
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
93
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
|
|
94
|
+
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
95
|
+
imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
97
|
+
chunkRPZWETTK_cjs.Zod,
|
|
98
|
+
{
|
|
99
|
+
name: zod.name,
|
|
100
|
+
typeName: typed ? type.name : void 0,
|
|
101
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
102
|
+
description: schema.value.description,
|
|
103
|
+
tree: schema.tree,
|
|
104
|
+
mapper,
|
|
105
|
+
coercion
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
] });
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
var pluginZodName = "plugin-zod";
|
|
112
|
+
var pluginZod = core.createPlugin((options) => {
|
|
113
|
+
const {
|
|
114
|
+
output = { path: "zod" },
|
|
115
|
+
group,
|
|
116
|
+
exclude = [],
|
|
117
|
+
include,
|
|
118
|
+
override = [],
|
|
119
|
+
transformers: transformers$1 = {},
|
|
120
|
+
dateType = "string",
|
|
121
|
+
unknownType = "any",
|
|
122
|
+
typed = false,
|
|
123
|
+
mapper = {},
|
|
124
|
+
operations = false,
|
|
125
|
+
importPath = "zod",
|
|
126
|
+
coercion = false,
|
|
127
|
+
inferred = false
|
|
128
|
+
} = options;
|
|
129
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
130
|
+
return {
|
|
131
|
+
name: pluginZodName,
|
|
132
|
+
options: {
|
|
133
|
+
output: {
|
|
134
|
+
exportType: "barrelNamed",
|
|
135
|
+
...output
|
|
136
|
+
},
|
|
137
|
+
extName: output.extName,
|
|
138
|
+
transformers: transformers$1,
|
|
139
|
+
include,
|
|
140
|
+
exclude,
|
|
141
|
+
override,
|
|
142
|
+
typed,
|
|
143
|
+
dateType,
|
|
144
|
+
unknownType,
|
|
145
|
+
mapper,
|
|
146
|
+
importPath,
|
|
147
|
+
coercion,
|
|
148
|
+
operations,
|
|
149
|
+
inferred
|
|
150
|
+
},
|
|
151
|
+
pre: [pluginOas.pluginOasName, typed ? pluginTs.pluginTsName : void 0].filter(Boolean),
|
|
152
|
+
resolvePath(baseName, pathMode, options2) {
|
|
153
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
154
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
155
|
+
if (mode === "single") {
|
|
156
|
+
return path__default.default.resolve(root, output.path);
|
|
157
|
+
}
|
|
158
|
+
if (options2?.tag && group?.type === "tag") {
|
|
159
|
+
const tag = transformers.camelCase(options2.tag);
|
|
160
|
+
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
161
|
+
}
|
|
162
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
163
|
+
},
|
|
164
|
+
resolveName(name, type) {
|
|
165
|
+
let resolvedName = transformers.camelCase(name, {
|
|
166
|
+
suffix: type ? "schema" : void 0,
|
|
167
|
+
isFile: type === "file"
|
|
168
|
+
});
|
|
169
|
+
if (type === "type") {
|
|
170
|
+
resolvedName = transformers.pascalCase(resolvedName);
|
|
171
|
+
}
|
|
172
|
+
if (type) {
|
|
173
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
174
|
+
}
|
|
175
|
+
return resolvedName;
|
|
176
|
+
},
|
|
177
|
+
async buildStart() {
|
|
178
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
179
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
180
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
181
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
182
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
183
|
+
oas,
|
|
184
|
+
pluginManager: this.pluginManager,
|
|
185
|
+
plugin: this.plugin,
|
|
186
|
+
contentType: swaggerPlugin.context.contentType,
|
|
187
|
+
include: void 0,
|
|
188
|
+
override,
|
|
189
|
+
mode,
|
|
190
|
+
output: output.path
|
|
191
|
+
});
|
|
192
|
+
const schemaFiles = await schemaGenerator.build(...[zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
193
|
+
await this.addFile(...schemaFiles);
|
|
194
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
195
|
+
oas,
|
|
196
|
+
pluginManager: this.pluginManager,
|
|
197
|
+
plugin: this.plugin,
|
|
198
|
+
contentType: swaggerPlugin.context.contentType,
|
|
199
|
+
exclude,
|
|
200
|
+
include,
|
|
201
|
+
override,
|
|
202
|
+
mode
|
|
203
|
+
});
|
|
204
|
+
const operationFiles = await operationGenerator.build(...[zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
205
|
+
await this.addFile(...operationFiles);
|
|
206
|
+
if (this.config.output.exportType) {
|
|
207
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
208
|
+
root,
|
|
209
|
+
output,
|
|
210
|
+
files: this.fileManager.files,
|
|
211
|
+
meta: {
|
|
212
|
+
pluginKey: this.plugin.key
|
|
213
|
+
},
|
|
214
|
+
logger: this.logger
|
|
215
|
+
});
|
|
216
|
+
await this.addFile(...barrelFiles);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
var operationsGenerator = pluginOas.createReactGenerator({
|
|
222
|
+
name: "operations",
|
|
223
|
+
Operations({ operations }) {
|
|
224
|
+
const {
|
|
225
|
+
pluginManager,
|
|
226
|
+
plugin: {
|
|
227
|
+
options: { output }
|
|
228
|
+
}
|
|
229
|
+
} = react.useApp();
|
|
230
|
+
const { getFile, groupSchemasByName } = hooks.useOperationManager();
|
|
231
|
+
const name = "operations";
|
|
232
|
+
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: [pluginZodName] });
|
|
233
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
234
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
235
|
+
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
236
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
237
|
+
}).filter(Boolean);
|
|
238
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
239
|
+
imports,
|
|
240
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkRPZWETTK_cjs.Operations, { name, operations: transformedOperations })
|
|
241
|
+
] });
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
exports.operationsGenerator = operationsGenerator;
|
|
246
|
+
exports.pluginZod = pluginZod;
|
|
247
|
+
exports.pluginZodName = pluginZodName;
|
|
248
|
+
exports.zodGenerator = zodGenerator;
|
|
249
|
+
//# sourceMappingURL=chunk-GILKYHDS.cjs.map
|
|
250
|
+
//# sourceMappingURL=chunk-GILKYHDS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","createPlugin","transformers","pluginOasName","path","FileManager","camelCase","renderTemplate","pascalCase","PluginManager","OperationGenerator","Operations"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,KAAA,EAAO,QAAW,GAAA,OAAA,CAAA;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA,CAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA,CAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAQ,EAAA,GAAIC,yBAAoB,EAAA,CAAA;AACpD,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA,CAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,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,OAAA,CAAQ,SAAS,CAAA,CAAE,QAA5D,GAAkE,CAAA,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAEjB,IAAA,uBACEG,eAACH,CAAAA,UAAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,UAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,EAAQ,QAAQ,MACtG,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACa,4BAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA,CAAA;AAAA,KAC7D,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-GILKYHDS.cjs","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion, inferred, typed, mapper } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required\n const optional = !required && !!name.includes('Params')\n const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\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, { type: 'type', pluginKey: [pluginTsName] }),\n file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], tag: options.operation?.getTags()[0]?.name }),\n }\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} 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 mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} 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 mapper={mapper}\n coercion={coercion}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginZodName,\n options: {\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n extName: output.extName,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\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 ?? FileManager.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 (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\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 buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...[zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean))\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...[zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean))\n await this.addFile(...operationFiles)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport { pluginZodName } from '../plugin.ts'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: [pluginZodName] })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { File, Const, Type } from '@kubb/react';
|
|
2
|
+
import transformers2 from '@kubb/core/transformers';
|
|
3
|
+
import { jsxs, Fragment, jsx } from '@kubb/react/jsx-runtime';
|
|
4
|
+
import { isKeyword, schemaKeywords } from '@kubb/plugin-oas';
|
|
5
|
+
|
|
6
|
+
// src/components/Operations.tsx
|
|
7
|
+
function Operations({ name, operations }) {
|
|
8
|
+
const operationsJSON = operations.reduce(
|
|
9
|
+
(prev, acc) => {
|
|
10
|
+
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
11
|
+
return prev;
|
|
12
|
+
},
|
|
13
|
+
{}
|
|
14
|
+
);
|
|
15
|
+
const pathsJSON = operations.reduce(
|
|
16
|
+
(prev, acc) => {
|
|
17
|
+
prev[`"${acc.operation.path}"`] = {
|
|
18
|
+
...prev[`"${acc.operation.path}"`] || {},
|
|
19
|
+
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
20
|
+
};
|
|
21
|
+
return prev;
|
|
22
|
+
},
|
|
23
|
+
{}
|
|
24
|
+
);
|
|
25
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
26
|
+
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name, asConst: true, children: `{${transformers2.stringifyObject(operationsJSON)}}` }) }),
|
|
27
|
+
/* @__PURE__ */ jsx(File.Source, { name: "paths", isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name: "paths", asConst: true, children: `{${transformers2.stringifyObject(pathsJSON)}}` }) })
|
|
28
|
+
] });
|
|
29
|
+
}
|
|
30
|
+
var zodKeywordMapper = {
|
|
31
|
+
any: () => "z.any()",
|
|
32
|
+
unknown: () => "z.unknown()",
|
|
33
|
+
number: (coercion, min, max) => {
|
|
34
|
+
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
35
|
+
},
|
|
36
|
+
integer: (coercion, min, max) => {
|
|
37
|
+
return [
|
|
38
|
+
coercion ? "z.coerce.number().int()" : "z.number().int()",
|
|
39
|
+
min !== void 0 ? `.min(${min})` : void 0,
|
|
40
|
+
max !== void 0 ? `.max(${max})` : void 0
|
|
41
|
+
].filter(Boolean).join("");
|
|
42
|
+
},
|
|
43
|
+
object: (value) => `z.object({${value}})`,
|
|
44
|
+
string: (coercion, min, max) => {
|
|
45
|
+
return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
46
|
+
},
|
|
47
|
+
boolean: () => "z.boolean()",
|
|
48
|
+
undefined: () => "z.undefined()",
|
|
49
|
+
nullable: () => ".nullable()",
|
|
50
|
+
null: () => "z.null()",
|
|
51
|
+
nullish: () => ".nullish()",
|
|
52
|
+
array: (items = [], min, max) => {
|
|
53
|
+
return [`z.array(${items?.join("")})`, min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
54
|
+
},
|
|
55
|
+
tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
|
|
56
|
+
enum: (items = []) => `z.enum([${items?.join(", ")}])`,
|
|
57
|
+
union: (items = []) => `z.union([${items?.join(", ")}])`,
|
|
58
|
+
const: (value) => `z.literal(${value ?? ""})`,
|
|
59
|
+
/**
|
|
60
|
+
* ISO 8601
|
|
61
|
+
*/
|
|
62
|
+
datetime: (offset = false, local = false) => {
|
|
63
|
+
if (offset) {
|
|
64
|
+
return `z.string().datetime({ offset: ${offset} })`;
|
|
65
|
+
}
|
|
66
|
+
if (local) {
|
|
67
|
+
return `z.string().datetime({ local: ${local} })`;
|
|
68
|
+
}
|
|
69
|
+
return "z.string().datetime()";
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Type `'date'` Date
|
|
73
|
+
* Type `'string'` ISO date format (YYYY-MM-DD)
|
|
74
|
+
* @default ISO date format (YYYY-MM-DD)
|
|
75
|
+
*/
|
|
76
|
+
date: (type = "string", coercion) => {
|
|
77
|
+
if (type === "string") {
|
|
78
|
+
return "z.string().date()";
|
|
79
|
+
}
|
|
80
|
+
if (coercion) {
|
|
81
|
+
return "z.coerce.date()";
|
|
82
|
+
}
|
|
83
|
+
return "z.date()";
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Type `'date'` Date
|
|
87
|
+
* Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
|
|
88
|
+
* @default ISO time format (HH:mm:ss[.SSSSSS])
|
|
89
|
+
*/
|
|
90
|
+
time: (type = "string", coercion) => {
|
|
91
|
+
if (type === "string") {
|
|
92
|
+
return "z.string().time()";
|
|
93
|
+
}
|
|
94
|
+
if (coercion) {
|
|
95
|
+
return "z.coerce.date()";
|
|
96
|
+
}
|
|
97
|
+
return "z.date()";
|
|
98
|
+
},
|
|
99
|
+
uuid: () => ".uuid()",
|
|
100
|
+
url: () => ".url()",
|
|
101
|
+
strict: () => ".strict()",
|
|
102
|
+
default: (value) => `.default(${value ?? ""})`,
|
|
103
|
+
and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
|
|
104
|
+
describe: (value = "") => `.describe(${value})`,
|
|
105
|
+
min: (value) => `.min(${value ?? ""})`,
|
|
106
|
+
max: (value) => `.max(${value ?? ""})`,
|
|
107
|
+
optional: () => ".optional()",
|
|
108
|
+
matches: (value = "") => `.regex(${value})`,
|
|
109
|
+
email: () => ".email()",
|
|
110
|
+
firstName: void 0,
|
|
111
|
+
lastName: void 0,
|
|
112
|
+
password: void 0,
|
|
113
|
+
phone: void 0,
|
|
114
|
+
readOnly: void 0,
|
|
115
|
+
ref: (value) => value ? `z.lazy(() => ${value})` : void 0,
|
|
116
|
+
blob: () => "z.string()",
|
|
117
|
+
deprecated: void 0,
|
|
118
|
+
example: void 0,
|
|
119
|
+
schema: void 0,
|
|
120
|
+
catchall: (value) => value ? `.catchall(${value})` : void 0,
|
|
121
|
+
name: void 0
|
|
122
|
+
};
|
|
123
|
+
function sort(items) {
|
|
124
|
+
const order = [
|
|
125
|
+
schemaKeywords.string,
|
|
126
|
+
schemaKeywords.datetime,
|
|
127
|
+
schemaKeywords.date,
|
|
128
|
+
schemaKeywords.time,
|
|
129
|
+
schemaKeywords.tuple,
|
|
130
|
+
schemaKeywords.number,
|
|
131
|
+
schemaKeywords.object,
|
|
132
|
+
schemaKeywords.enum,
|
|
133
|
+
schemaKeywords.url,
|
|
134
|
+
schemaKeywords.email,
|
|
135
|
+
schemaKeywords.firstName,
|
|
136
|
+
schemaKeywords.lastName,
|
|
137
|
+
schemaKeywords.password,
|
|
138
|
+
schemaKeywords.matches,
|
|
139
|
+
schemaKeywords.uuid,
|
|
140
|
+
schemaKeywords.min,
|
|
141
|
+
schemaKeywords.max,
|
|
142
|
+
schemaKeywords.default,
|
|
143
|
+
schemaKeywords.describe,
|
|
144
|
+
schemaKeywords.optional,
|
|
145
|
+
schemaKeywords.nullable,
|
|
146
|
+
schemaKeywords.nullish,
|
|
147
|
+
schemaKeywords.null
|
|
148
|
+
];
|
|
149
|
+
if (!items) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
return transformers2.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
153
|
+
}
|
|
154
|
+
function parse(parent, current, options) {
|
|
155
|
+
const value = zodKeywordMapper[current.keyword];
|
|
156
|
+
if (!value) {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
if (isKeyword(current, schemaKeywords.union)) {
|
|
160
|
+
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
161
|
+
return parse(parent, current.args[0], options);
|
|
162
|
+
}
|
|
163
|
+
if (Array.isArray(current.args) && !current.args.length) {
|
|
164
|
+
return "";
|
|
165
|
+
}
|
|
166
|
+
return zodKeywordMapper.union(
|
|
167
|
+
sort(current.args).map((schema) => parse(current, schema, options)).filter(Boolean)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (isKeyword(current, schemaKeywords.and)) {
|
|
171
|
+
const items = sort(current.args).filter((schema) => {
|
|
172
|
+
return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword);
|
|
173
|
+
}).map((schema) => parse(current, schema, options)).filter(Boolean);
|
|
174
|
+
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
175
|
+
}
|
|
176
|
+
if (isKeyword(current, schemaKeywords.array)) {
|
|
177
|
+
return zodKeywordMapper.array(
|
|
178
|
+
sort(current.args.items).map((schemas) => parse(current, schemas, options)).filter(Boolean),
|
|
179
|
+
current.args.min,
|
|
180
|
+
current.args.max
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (isKeyword(current, schemaKeywords.enum)) {
|
|
184
|
+
if (current.args.asConst) {
|
|
185
|
+
return zodKeywordMapper.union(
|
|
186
|
+
current.args.items.map((schema) => {
|
|
187
|
+
return parse(
|
|
188
|
+
current,
|
|
189
|
+
{
|
|
190
|
+
keyword: schemaKeywords.const,
|
|
191
|
+
args: schema
|
|
192
|
+
},
|
|
193
|
+
options
|
|
194
|
+
);
|
|
195
|
+
}).filter(Boolean)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return zodKeywordMapper.enum(
|
|
199
|
+
current.args.items.map((schema) => {
|
|
200
|
+
if (schema.format === "number") {
|
|
201
|
+
return transformers2.stringify(schema.value);
|
|
202
|
+
}
|
|
203
|
+
return transformers2.stringify(schema.value);
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (isKeyword(current, schemaKeywords.ref)) {
|
|
208
|
+
return zodKeywordMapper.ref(current.args?.name);
|
|
209
|
+
}
|
|
210
|
+
if (isKeyword(current, schemaKeywords.object)) {
|
|
211
|
+
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
212
|
+
const schema = item[1];
|
|
213
|
+
return schema && typeof schema.map === "function";
|
|
214
|
+
}).map(([name, schemas]) => {
|
|
215
|
+
const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
|
|
216
|
+
const mappedName = nameSchema?.args || name;
|
|
217
|
+
if (options.mapper?.[mappedName]) {
|
|
218
|
+
return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
219
|
+
}
|
|
220
|
+
return `"${name}": ${sort(schemas).map((schema, array) => {
|
|
221
|
+
return parse(current, schema, options);
|
|
222
|
+
}).filter(Boolean).join("")}`;
|
|
223
|
+
}).join(",");
|
|
224
|
+
const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0) : void 0;
|
|
225
|
+
const text = [
|
|
226
|
+
zodKeywordMapper.object(properties),
|
|
227
|
+
current.args?.strict ? zodKeywordMapper.strict() : void 0,
|
|
228
|
+
additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
|
|
229
|
+
].filter(Boolean);
|
|
230
|
+
return text.join("");
|
|
231
|
+
}
|
|
232
|
+
if (isKeyword(current, schemaKeywords.tuple)) {
|
|
233
|
+
return zodKeywordMapper.tuple(
|
|
234
|
+
sort(current.args.items).map((schema) => parse(current, schema, options)).filter(Boolean)
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
if (isKeyword(current, schemaKeywords.const)) {
|
|
238
|
+
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
239
|
+
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
240
|
+
}
|
|
241
|
+
return zodKeywordMapper.const(transformers2.stringify(current.args.value));
|
|
242
|
+
}
|
|
243
|
+
if (isKeyword(current, schemaKeywords.matches)) {
|
|
244
|
+
if (current.args) {
|
|
245
|
+
return zodKeywordMapper.matches(transformers2.toRegExpString(current.args));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (isKeyword(current, schemaKeywords.default)) {
|
|
249
|
+
if (current.args) {
|
|
250
|
+
return zodKeywordMapper.default(current.args);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (isKeyword(current, schemaKeywords.describe)) {
|
|
254
|
+
if (current.args) {
|
|
255
|
+
return zodKeywordMapper.describe(transformers2.stringify(current.args.toString()));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (isKeyword(current, schemaKeywords.string)) {
|
|
259
|
+
return zodKeywordMapper.string(options.coercion);
|
|
260
|
+
}
|
|
261
|
+
if (isKeyword(current, schemaKeywords.number)) {
|
|
262
|
+
return zodKeywordMapper.number(options.coercion);
|
|
263
|
+
}
|
|
264
|
+
if (isKeyword(current, schemaKeywords.integer)) {
|
|
265
|
+
return zodKeywordMapper.integer(options.coercion);
|
|
266
|
+
}
|
|
267
|
+
if (isKeyword(current, schemaKeywords.min)) {
|
|
268
|
+
return zodKeywordMapper.min(current.args);
|
|
269
|
+
}
|
|
270
|
+
if (isKeyword(current, schemaKeywords.max)) {
|
|
271
|
+
return zodKeywordMapper.max(current.args);
|
|
272
|
+
}
|
|
273
|
+
if (isKeyword(current, schemaKeywords.datetime)) {
|
|
274
|
+
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
275
|
+
}
|
|
276
|
+
if (isKeyword(current, schemaKeywords.date)) {
|
|
277
|
+
return zodKeywordMapper.date(current.args.type, options.coercion);
|
|
278
|
+
}
|
|
279
|
+
if (isKeyword(current, schemaKeywords.time)) {
|
|
280
|
+
return zodKeywordMapper.time(current.args.type, options.coercion);
|
|
281
|
+
}
|
|
282
|
+
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
283
|
+
const value2 = zodKeywordMapper[current.keyword];
|
|
284
|
+
return value2(current.args);
|
|
285
|
+
}
|
|
286
|
+
if (current.keyword in zodKeywordMapper) {
|
|
287
|
+
return value();
|
|
288
|
+
}
|
|
289
|
+
return void 0;
|
|
290
|
+
}
|
|
291
|
+
function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }) {
|
|
292
|
+
const hasTuple = tree.some((item) => isKeyword(item, schemaKeywords.tuple));
|
|
293
|
+
const output = sort(tree).filter((item) => {
|
|
294
|
+
if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}).map((item) => parse(void 0, item, { name, keysToOmit, typeName, description, mapper, coercion })).filter(Boolean).join("");
|
|
299
|
+
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
300
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
301
|
+
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
|
|
302
|
+
Const,
|
|
303
|
+
{
|
|
304
|
+
export: true,
|
|
305
|
+
name,
|
|
306
|
+
JSDoc: {
|
|
307
|
+
comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
308
|
+
},
|
|
309
|
+
children: [
|
|
310
|
+
output,
|
|
311
|
+
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
|
|
312
|
+
typeName ? ` as z.ZodType<${typeName}>` : ""
|
|
313
|
+
].filter(Boolean).join("") || ""
|
|
314
|
+
}
|
|
315
|
+
) }),
|
|
316
|
+
inferTypeName && /* @__PURE__ */ jsx(File.Source, { name: inferTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { export: true, name: inferTypeName, children: `z.infer<typeof ${name}>` }) })
|
|
317
|
+
] });
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { Operations, Zod };
|
|
321
|
+
//# sourceMappingURL=chunk-KGKZCQKF.js.map
|
|
322
|
+
//# sourceMappingURL=chunk-KGKZCQKF.js.map
|