@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 CHANGED
@@ -11,8 +11,8 @@ var __name = (target, value) => __defProp(target, "name", {
11
11
  //#endregion
12
12
  let _kubb_core = require("@kubb/core");
13
13
  let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
14
- let _kubb_ast_utils = require("@kubb/ast/utils");
15
14
  let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
15
+ let _kubb_ast_utils = require("@kubb/ast/utils");
16
16
  //#region ../../internals/utils/src/casing.ts
17
17
  /**
18
18
  * Shared implementation for camelCase and PascalCase conversion.
@@ -313,80 +313,6 @@ function createGroupConfig(group) {
313
313
  };
314
314
  }
315
315
  //#endregion
316
- //#region src/components/Operations.tsx
317
- function Operations({ name, operations }) {
318
- const operationsJSON = operations.reduce((prev, acc) => {
319
- prev[`"${acc.node.operationId}"`] = acc.data;
320
- return prev;
321
- }, {});
322
- const pathsJSON = operations.reduce((prev, acc) => {
323
- if (!_kubb_core.ast.isHttpOperationNode(acc.node)) return prev;
324
- prev[`"${acc.node.path}"`] = {
325
- ...prev[`"${acc.node.path}"`] ?? {},
326
- [acc.node.method]: `operations["${acc.node.operationId}"]`
327
- };
328
- return prev;
329
- }, {});
330
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
331
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
332
- name: "OperationSchema",
333
- isExportable: true,
334
- isIndexable: true,
335
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
336
- name: "OperationSchema",
337
- export: true,
338
- children: `{
339
- readonly request: z.ZodTypeAny | undefined;
340
- readonly parameters: {
341
- readonly path: z.ZodTypeAny | undefined;
342
- readonly query: z.ZodTypeAny | undefined;
343
- readonly header: z.ZodTypeAny | undefined;
344
- };
345
- readonly responses: {
346
- readonly [status: number]: z.ZodTypeAny;
347
- readonly default: z.ZodTypeAny;
348
- };
349
- readonly errors: {
350
- readonly [status: number]: z.ZodTypeAny;
351
- };
352
- }`
353
- })
354
- }),
355
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
356
- name: "OperationsMap",
357
- isExportable: true,
358
- isIndexable: true,
359
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
360
- name: "OperationsMap",
361
- export: true,
362
- children: "Record<string, OperationSchema>"
363
- })
364
- }),
365
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
366
- name,
367
- isExportable: true,
368
- isIndexable: true,
369
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Const, {
370
- export: true,
371
- name,
372
- asConst: true,
373
- children: `{${(0, _kubb_ast_utils.stringifyObject)(operationsJSON)}}`
374
- })
375
- }),
376
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
377
- name: "paths",
378
- isExportable: true,
379
- isIndexable: true,
380
- children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Const, {
381
- export: true,
382
- name: "paths",
383
- asConst: true,
384
- children: `{${(0, _kubb_ast_utils.stringifyObject)(pathsJSON)}}`
385
- })
386
- })
387
- ] });
388
- }
389
- //#endregion
390
316
  //#region src/components/Zod.tsx
391
317
  function Zod({ name, node, printer, inferTypeName }) {
392
318
  const output = printer.print(node);
@@ -492,36 +418,6 @@ function collectCodecRefNames(node) {
492
418
  return _kubb_core.ast.collect(node, { schema: (n) => n.type === "ref" && n.ref && containsCodec(n) ? (0, _kubb_ast_utils.extractRefName)(n.ref) ?? void 0 : void 0 });
493
419
  }
494
420
  /**
495
- * Collects all resolved schema names for an operation's parameters and responses
496
- * into a single lookup object, useful for building imports and type references.
497
- */
498
- function buildSchemaNames(node, { params, resolver }) {
499
- const pathParam = params.find((p) => p.in === "path");
500
- const queryParam = params.find((p) => p.in === "query");
501
- const headerParam = params.find((p) => p.in === "header");
502
- const responses = {};
503
- const errors = {};
504
- for (const res of node.responses) {
505
- const name = resolver.resolveResponseStatusName(node, res.statusCode);
506
- const statusNum = Number(res.statusCode);
507
- if (!Number.isNaN(statusNum)) {
508
- responses[statusNum] = name;
509
- if (statusNum >= 400) errors[statusNum] = name;
510
- }
511
- }
512
- responses["default"] = resolver.resolveResponseName(node);
513
- return {
514
- request: node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null,
515
- parameters: {
516
- path: pathParam ? resolver.resolvePathParamsName(node, pathParam) : null,
517
- query: queryParam ? resolver.resolveQueryParamsName(node, queryParam) : null,
518
- header: headerParam ? resolver.resolveHeaderParamsName(node, headerParam) : null
519
- },
520
- responses,
521
- errors
522
- };
523
- }
524
- /**
525
421
  * Format a default value as a code-level literal.
526
422
  * Objects become `{}`, primitives become their string representation, strings are quoted.
527
423
  */
@@ -1394,85 +1290,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
1394
1290
  requestSchema
1395
1291
  ]
1396
1292
  });
1397
- },
1398
- operations(nodes, ctx) {
1399
- const { config, resolver, root } = ctx;
1400
- const { output, importPath, group, operations } = ctx.options;
1401
- if (!operations) return;
1402
- const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1403
- const meta = { file: resolver.resolveFile({
1404
- name: "operations",
1405
- extname: ".ts"
1406
- }, {
1407
- root,
1408
- output,
1409
- group: group ?? void 0
1410
- }) };
1411
- const transformedOperations = nodes.filter(_kubb_core.ast.isHttpOperationNode).map((node) => {
1412
- return {
1413
- node,
1414
- data: buildSchemaNames(node, {
1415
- params: caseParams(node.parameters, "camelcase"),
1416
- resolver
1417
- })
1418
- };
1419
- });
1420
- const imports = transformedOperations.flatMap(({ node, data }) => {
1421
- const names = [
1422
- data.request,
1423
- ...Object.values(data.responses),
1424
- ...Object.values(data.parameters)
1425
- ].filter(Boolean);
1426
- const opFile = resolver.resolveFile({
1427
- name: node.operationId,
1428
- extname: ".ts",
1429
- tag: node.tags[0] ?? "default",
1430
- path: node.path
1431
- }, {
1432
- root,
1433
- output,
1434
- group: group ?? void 0
1435
- });
1436
- return names.map((name) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1437
- name: [name],
1438
- root: meta.file.path,
1439
- path: opFile.path
1440
- }, [name, opFile.path].join("-")));
1441
- });
1442
- return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
1443
- baseName: meta.file.baseName,
1444
- path: meta.file.path,
1445
- meta: meta.file.meta,
1446
- banner: resolver.resolveBanner(ctx.meta, {
1447
- output,
1448
- config,
1449
- file: {
1450
- path: meta.file.path,
1451
- baseName: meta.file.baseName
1452
- }
1453
- }),
1454
- footer: resolver.resolveFooter(ctx.meta, {
1455
- output,
1456
- config,
1457
- file: {
1458
- path: meta.file.path,
1459
- baseName: meta.file.baseName
1460
- }
1461
- }),
1462
- children: [
1463
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1464
- isTypeOnly: true,
1465
- name: isZodImport ? "z" : ["z"],
1466
- path: importPath,
1467
- isNameSpace: isZodImport
1468
- }),
1469
- imports,
1470
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Operations, {
1471
- name: "operations",
1472
- operations: transformedOperations
1473
- })
1474
- ]
1475
- });
1476
1293
  }
1477
1294
  });
1478
1295
  //#endregion
@@ -1581,7 +1398,7 @@ const pluginZod = (0, _kubb_core.definePlugin)((options) => {
1581
1398
  const { output = {
1582
1399
  path: "zod",
1583
1400
  barrel: { type: "named" }
1584
- }, group, exclude = [], include, override = [], typed = false, operations = 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;
1401
+ }, 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;
1585
1402
  const groupConfig = createGroupConfig(group);
1586
1403
  return {
1587
1404
  name: pluginZodName,
@@ -1596,7 +1413,6 @@ const pluginZod = (0, _kubb_core.definePlugin)((options) => {
1596
1413
  typed,
1597
1414
  importPath,
1598
1415
  coercion,
1599
- operations,
1600
1416
  inferred,
1601
1417
  guidType,
1602
1418
  regexType,