@kubb/plugin-zod 5.0.0-beta.74 → 5.0.0-beta.75
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 +2 -186
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +2 -186
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -355,11 +355,6 @@ type Options = OutputOptions & {
|
|
|
355
355
|
strings?: boolean;
|
|
356
356
|
numbers?: boolean;
|
|
357
357
|
};
|
|
358
|
-
/**
|
|
359
|
-
* Emit an `operations.ts` file with request body, query/path params, and per-status
|
|
360
|
-
* response schemas grouped by operation.
|
|
361
|
-
*/
|
|
362
|
-
operations?: boolean;
|
|
363
358
|
/**
|
|
364
359
|
* Validator for `format: uuid` properties.
|
|
365
360
|
* - `'uuid'` — `z.uuid()`. Standard RFC 4122.
|
|
@@ -420,7 +415,6 @@ type ResolvedOptions = {
|
|
|
420
415
|
inferred: NonNullable<Options['inferred']>;
|
|
421
416
|
importPath: NonNullable<Options['importPath']>;
|
|
422
417
|
coercion: NonNullable<Options['coercion']>;
|
|
423
|
-
operations: NonNullable<Options['operations']>;
|
|
424
418
|
guidType: NonNullable<Options['guidType']>;
|
|
425
419
|
regexType: NonNullable<Options['regexType']>;
|
|
426
420
|
mini: NonNullable<Options['mini']>;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
|
|
3
3
|
import { Const, File, Type, jsxRenderer } from "@kubb/renderer-jsx";
|
|
4
|
-
import { buildList, buildObject, containsCircularRef, extractRefName, lazyGetter, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, objectKey, stringify, stringifyObject, syncSchemaRef, toRegExpString } from "@kubb/ast/utils";
|
|
5
4
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
5
|
+
import { buildList, buildObject, containsCircularRef, extractRefName, lazyGetter, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, objectKey, stringify, syncSchemaRef, toRegExpString } from "@kubb/ast/utils";
|
|
6
6
|
//#region ../../internals/utils/src/casing.ts
|
|
7
7
|
/**
|
|
8
8
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -303,80 +303,6 @@ function createGroupConfig(group) {
|
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
305
|
//#endregion
|
|
306
|
-
//#region src/components/Operations.tsx
|
|
307
|
-
function Operations({ name, operations }) {
|
|
308
|
-
const operationsJSON = operations.reduce((prev, acc) => {
|
|
309
|
-
prev[`"${acc.node.operationId}"`] = acc.data;
|
|
310
|
-
return prev;
|
|
311
|
-
}, {});
|
|
312
|
-
const pathsJSON = operations.reduce((prev, acc) => {
|
|
313
|
-
if (!ast.isHttpOperationNode(acc.node)) return prev;
|
|
314
|
-
prev[`"${acc.node.path}"`] = {
|
|
315
|
-
...prev[`"${acc.node.path}"`] ?? {},
|
|
316
|
-
[acc.node.method]: `operations["${acc.node.operationId}"]`
|
|
317
|
-
};
|
|
318
|
-
return prev;
|
|
319
|
-
}, {});
|
|
320
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
321
|
-
/* @__PURE__ */ jsx(File.Source, {
|
|
322
|
-
name: "OperationSchema",
|
|
323
|
-
isExportable: true,
|
|
324
|
-
isIndexable: true,
|
|
325
|
-
children: /* @__PURE__ */ jsx(Type, {
|
|
326
|
-
name: "OperationSchema",
|
|
327
|
-
export: true,
|
|
328
|
-
children: `{
|
|
329
|
-
readonly request: z.ZodTypeAny | undefined;
|
|
330
|
-
readonly parameters: {
|
|
331
|
-
readonly path: z.ZodTypeAny | undefined;
|
|
332
|
-
readonly query: z.ZodTypeAny | undefined;
|
|
333
|
-
readonly header: z.ZodTypeAny | undefined;
|
|
334
|
-
};
|
|
335
|
-
readonly responses: {
|
|
336
|
-
readonly [status: number]: z.ZodTypeAny;
|
|
337
|
-
readonly default: z.ZodTypeAny;
|
|
338
|
-
};
|
|
339
|
-
readonly errors: {
|
|
340
|
-
readonly [status: number]: z.ZodTypeAny;
|
|
341
|
-
};
|
|
342
|
-
}`
|
|
343
|
-
})
|
|
344
|
-
}),
|
|
345
|
-
/* @__PURE__ */ jsx(File.Source, {
|
|
346
|
-
name: "OperationsMap",
|
|
347
|
-
isExportable: true,
|
|
348
|
-
isIndexable: true,
|
|
349
|
-
children: /* @__PURE__ */ jsx(Type, {
|
|
350
|
-
name: "OperationsMap",
|
|
351
|
-
export: true,
|
|
352
|
-
children: "Record<string, OperationSchema>"
|
|
353
|
-
})
|
|
354
|
-
}),
|
|
355
|
-
/* @__PURE__ */ jsx(File.Source, {
|
|
356
|
-
name,
|
|
357
|
-
isExportable: true,
|
|
358
|
-
isIndexable: true,
|
|
359
|
-
children: /* @__PURE__ */ jsx(Const, {
|
|
360
|
-
export: true,
|
|
361
|
-
name,
|
|
362
|
-
asConst: true,
|
|
363
|
-
children: `{${stringifyObject(operationsJSON)}}`
|
|
364
|
-
})
|
|
365
|
-
}),
|
|
366
|
-
/* @__PURE__ */ jsx(File.Source, {
|
|
367
|
-
name: "paths",
|
|
368
|
-
isExportable: true,
|
|
369
|
-
isIndexable: true,
|
|
370
|
-
children: /* @__PURE__ */ jsx(Const, {
|
|
371
|
-
export: true,
|
|
372
|
-
name: "paths",
|
|
373
|
-
asConst: true,
|
|
374
|
-
children: `{${stringifyObject(pathsJSON)}}`
|
|
375
|
-
})
|
|
376
|
-
})
|
|
377
|
-
] });
|
|
378
|
-
}
|
|
379
|
-
//#endregion
|
|
380
306
|
//#region src/components/Zod.tsx
|
|
381
307
|
function Zod({ name, node, printer, inferTypeName }) {
|
|
382
308
|
const output = printer.print(node);
|
|
@@ -482,36 +408,6 @@ function collectCodecRefNames(node) {
|
|
|
482
408
|
return ast.collect(node, { schema: (n) => n.type === "ref" && n.ref && containsCodec(n) ? extractRefName(n.ref) ?? void 0 : void 0 });
|
|
483
409
|
}
|
|
484
410
|
/**
|
|
485
|
-
* Collects all resolved schema names for an operation's parameters and responses
|
|
486
|
-
* into a single lookup object, useful for building imports and type references.
|
|
487
|
-
*/
|
|
488
|
-
function buildSchemaNames(node, { params, resolver }) {
|
|
489
|
-
const pathParam = params.find((p) => p.in === "path");
|
|
490
|
-
const queryParam = params.find((p) => p.in === "query");
|
|
491
|
-
const headerParam = params.find((p) => p.in === "header");
|
|
492
|
-
const responses = {};
|
|
493
|
-
const errors = {};
|
|
494
|
-
for (const res of node.responses) {
|
|
495
|
-
const name = resolver.resolveResponseStatusName(node, res.statusCode);
|
|
496
|
-
const statusNum = Number(res.statusCode);
|
|
497
|
-
if (!Number.isNaN(statusNum)) {
|
|
498
|
-
responses[statusNum] = name;
|
|
499
|
-
if (statusNum >= 400) errors[statusNum] = name;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
responses["default"] = resolver.resolveResponseName(node);
|
|
503
|
-
return {
|
|
504
|
-
request: node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null,
|
|
505
|
-
parameters: {
|
|
506
|
-
path: pathParam ? resolver.resolvePathParamsName(node, pathParam) : null,
|
|
507
|
-
query: queryParam ? resolver.resolveQueryParamsName(node, queryParam) : null,
|
|
508
|
-
header: headerParam ? resolver.resolveHeaderParamsName(node, headerParam) : null
|
|
509
|
-
},
|
|
510
|
-
responses,
|
|
511
|
-
errors
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
411
|
* Format a default value as a code-level literal.
|
|
516
412
|
* Objects become `{}`, primitives become their string representation, strings are quoted.
|
|
517
413
|
*/
|
|
@@ -1384,85 +1280,6 @@ const zodGenerator = defineGenerator({
|
|
|
1384
1280
|
requestSchema
|
|
1385
1281
|
]
|
|
1386
1282
|
});
|
|
1387
|
-
},
|
|
1388
|
-
operations(nodes, ctx) {
|
|
1389
|
-
const { config, resolver, root } = ctx;
|
|
1390
|
-
const { output, importPath, group, operations } = ctx.options;
|
|
1391
|
-
if (!operations) return;
|
|
1392
|
-
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
1393
|
-
const meta = { file: resolver.resolveFile({
|
|
1394
|
-
name: "operations",
|
|
1395
|
-
extname: ".ts"
|
|
1396
|
-
}, {
|
|
1397
|
-
root,
|
|
1398
|
-
output,
|
|
1399
|
-
group: group ?? void 0
|
|
1400
|
-
}) };
|
|
1401
|
-
const transformedOperations = nodes.filter(ast.isHttpOperationNode).map((node) => {
|
|
1402
|
-
return {
|
|
1403
|
-
node,
|
|
1404
|
-
data: buildSchemaNames(node, {
|
|
1405
|
-
params: caseParams(node.parameters, "camelcase"),
|
|
1406
|
-
resolver
|
|
1407
|
-
})
|
|
1408
|
-
};
|
|
1409
|
-
});
|
|
1410
|
-
const imports = transformedOperations.flatMap(({ node, data }) => {
|
|
1411
|
-
const names = [
|
|
1412
|
-
data.request,
|
|
1413
|
-
...Object.values(data.responses),
|
|
1414
|
-
...Object.values(data.parameters)
|
|
1415
|
-
].filter(Boolean);
|
|
1416
|
-
const opFile = resolver.resolveFile({
|
|
1417
|
-
name: node.operationId,
|
|
1418
|
-
extname: ".ts",
|
|
1419
|
-
tag: node.tags[0] ?? "default",
|
|
1420
|
-
path: node.path
|
|
1421
|
-
}, {
|
|
1422
|
-
root,
|
|
1423
|
-
output,
|
|
1424
|
-
group: group ?? void 0
|
|
1425
|
-
});
|
|
1426
|
-
return names.map((name) => /* @__PURE__ */ jsx(File.Import, {
|
|
1427
|
-
name: [name],
|
|
1428
|
-
root: meta.file.path,
|
|
1429
|
-
path: opFile.path
|
|
1430
|
-
}, [name, opFile.path].join("-")));
|
|
1431
|
-
});
|
|
1432
|
-
return /* @__PURE__ */ jsxs(File, {
|
|
1433
|
-
baseName: meta.file.baseName,
|
|
1434
|
-
path: meta.file.path,
|
|
1435
|
-
meta: meta.file.meta,
|
|
1436
|
-
banner: resolver.resolveBanner(ctx.meta, {
|
|
1437
|
-
output,
|
|
1438
|
-
config,
|
|
1439
|
-
file: {
|
|
1440
|
-
path: meta.file.path,
|
|
1441
|
-
baseName: meta.file.baseName
|
|
1442
|
-
}
|
|
1443
|
-
}),
|
|
1444
|
-
footer: resolver.resolveFooter(ctx.meta, {
|
|
1445
|
-
output,
|
|
1446
|
-
config,
|
|
1447
|
-
file: {
|
|
1448
|
-
path: meta.file.path,
|
|
1449
|
-
baseName: meta.file.baseName
|
|
1450
|
-
}
|
|
1451
|
-
}),
|
|
1452
|
-
children: [
|
|
1453
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
1454
|
-
isTypeOnly: true,
|
|
1455
|
-
name: isZodImport ? "z" : ["z"],
|
|
1456
|
-
path: importPath,
|
|
1457
|
-
isNameSpace: isZodImport
|
|
1458
|
-
}),
|
|
1459
|
-
imports,
|
|
1460
|
-
/* @__PURE__ */ jsx(Operations, {
|
|
1461
|
-
name: "operations",
|
|
1462
|
-
operations: transformedOperations
|
|
1463
|
-
})
|
|
1464
|
-
]
|
|
1465
|
-
});
|
|
1466
1283
|
}
|
|
1467
1284
|
});
|
|
1468
1285
|
//#endregion
|
|
@@ -1571,7 +1388,7 @@ const pluginZod = definePlugin((options) => {
|
|
|
1571
1388
|
const { output = {
|
|
1572
1389
|
path: "zod",
|
|
1573
1390
|
barrel: { type: "named" }
|
|
1574
|
-
}, group, exclude = [], include, override = [], typed = false,
|
|
1391
|
+
}, group, exclude = [], include, override = [], typed = false, mini = false, guidType = "uuid", regexType = "literal", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, printer, resolver: userResolver, macros: userMacros } = options;
|
|
1575
1392
|
const groupConfig = createGroupConfig(group);
|
|
1576
1393
|
return {
|
|
1577
1394
|
name: pluginZodName,
|
|
@@ -1586,7 +1403,6 @@ const pluginZod = definePlugin((options) => {
|
|
|
1586
1403
|
typed,
|
|
1587
1404
|
importPath,
|
|
1588
1405
|
coercion,
|
|
1589
|
-
operations,
|
|
1590
1406
|
inferred,
|
|
1591
1407
|
guidType,
|
|
1592
1408
|
regexType,
|