@kubb/plugin-zod 5.0.0-beta.10 → 5.0.0-beta.22
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 +142 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +143 -128
- package/dist/index.js.map +1 -1
- package/extension.yaml +21 -1
- package/package.json +5 -5
- package/src/generators/zodGenerator.tsx +51 -18
- package/src/printers/printerZod.ts +40 -62
- package/src/printers/printerZodMini.ts +30 -48
- package/src/utils.ts +14 -30
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
|
|
3
|
-
import { Const, File, Type,
|
|
3
|
+
import { Const, File, Type, jsxRendererSync } from "@kubb/renderer-jsx";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
5
5
|
//#region ../../internals/utils/src/casing.ts
|
|
6
6
|
/**
|
|
@@ -339,27 +339,26 @@ function lengthChecksMini({ min, max, pattern }) {
|
|
|
339
339
|
* to a schema value string using the chainable Zod v4 API.
|
|
340
340
|
*/
|
|
341
341
|
function applyModifiers({ value, nullable, optional, nullish, defaultValue, description }) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
342
|
+
const withModifier = (() => {
|
|
343
|
+
if (nullish || nullable && optional) return `${value}.nullish()`;
|
|
344
|
+
if (optional) return `${value}.optional()`;
|
|
345
|
+
if (nullable) return `${value}.nullable()`;
|
|
346
|
+
return value;
|
|
347
|
+
})();
|
|
348
|
+
const withDefault = defaultValue !== void 0 ? `${withModifier}.default(${formatDefault(defaultValue)})` : withModifier;
|
|
349
|
+
return description ? `${withDefault}.describe(${stringify(description)})` : withDefault;
|
|
349
350
|
}
|
|
350
351
|
/**
|
|
351
352
|
* Apply nullable / optional / nullish modifiers using the functional `zod/mini` API
|
|
352
353
|
* (`z.nullable()`, `z.optional()`, `z.nullish()`).
|
|
353
354
|
*/
|
|
354
355
|
function applyMiniModifiers({ value, nullable, optional, nullish, defaultValue }) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
if (defaultValue !== void 0) result = `z._default(${result}, ${formatDefault(defaultValue)})`;
|
|
362
|
-
return result;
|
|
356
|
+
const withModifier = (() => {
|
|
357
|
+
if (nullish) return `z.nullish(${value})`;
|
|
358
|
+
const withNullable = nullable ? `z.nullable(${value})` : value;
|
|
359
|
+
return optional ? `z.optional(${withNullable})` : withNullable;
|
|
360
|
+
})();
|
|
361
|
+
return defaultValue !== void 0 ? `z._default(${withModifier}, ${formatDefault(defaultValue)})` : withModifier;
|
|
363
362
|
}
|
|
364
363
|
//#endregion
|
|
365
364
|
//#region src/printers/printerZod.ts
|
|
@@ -373,6 +372,11 @@ function strictOneOfMember$1(member, node) {
|
|
|
373
372
|
return member;
|
|
374
373
|
}
|
|
375
374
|
__name(strictOneOfMember$1, "strictOneOfMember");
|
|
375
|
+
function getMemberConstraint(member) {
|
|
376
|
+
if (member.primitive === "string") return lengthConstraints(ast.narrowSchema(member, "string") ?? {}) || void 0;
|
|
377
|
+
if (member.primitive === "number" || member.primitive === "integer") return numberConstraints(ast.narrowSchema(member, "number") ?? ast.narrowSchema(member, "integer") ?? {}) || void 0;
|
|
378
|
+
if (member.primitive === "array") return lengthConstraints(ast.narrowSchema(member, "array") ?? {}) || void 0;
|
|
379
|
+
}
|
|
376
380
|
/**
|
|
377
381
|
* Zod v4 printer built with `definePrinter`.
|
|
378
382
|
*
|
|
@@ -445,29 +449,29 @@ const printerZod = ast.definePrinter((options) => {
|
|
|
445
449
|
return `z.enum([${nonNullValues.map(formatLiteral).join(", ")}])`;
|
|
446
450
|
},
|
|
447
451
|
ref(node) {
|
|
448
|
-
if (!node.name) return
|
|
452
|
+
if (!node.name) return null;
|
|
449
453
|
const refName = node.ref ? ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
450
454
|
const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
|
|
451
455
|
if (node.ref && this.options.cyclicSchemas?.has(refName)) return `z.lazy(() => ${resolvedName})`;
|
|
452
456
|
return resolvedName;
|
|
453
457
|
},
|
|
454
458
|
object(node) {
|
|
455
|
-
|
|
459
|
+
const objectBase = `z.object({\n ${node.properties.map((prop) => {
|
|
456
460
|
const { name: propName, schema } = prop;
|
|
457
461
|
const meta = ast.syncSchemaRef(schema);
|
|
458
462
|
const isNullable = meta.nullable;
|
|
459
463
|
const isOptional = schema.optional;
|
|
460
464
|
const isNullish = schema.nullish;
|
|
461
465
|
const hasSelfRef = this.options.cyclicSchemas != null && ast.containsCircularRef(schema, { circularSchemas: this.options.cyclicSchemas });
|
|
466
|
+
const savedCyclicSchemas = this.options.cyclicSchemas;
|
|
462
467
|
if (hasSelfRef) this.options.cyclicSchemas = void 0;
|
|
463
468
|
const baseOutput = this.transform(schema) ?? this.transform(ast.createSchema({ type: "unknown" }));
|
|
464
|
-
if (hasSelfRef) this.options.cyclicSchemas =
|
|
469
|
+
if (hasSelfRef) this.options.cyclicSchemas = savedCyclicSchemas;
|
|
465
470
|
const wrappedOutput = this.options.wrapOutput ? this.options.wrapOutput({
|
|
466
471
|
output: baseOutput,
|
|
467
472
|
schema
|
|
468
473
|
}) || baseOutput : baseOutput;
|
|
469
|
-
|
|
470
|
-
if (schema.type !== "ref" && meta.type === "ref") descriptionToApply = void 0;
|
|
474
|
+
const descriptionToApply = schema.type !== "ref" && meta.type === "ref" ? void 0 : meta.description;
|
|
471
475
|
const value = applyModifiers({
|
|
472
476
|
value: wrappedOutput,
|
|
473
477
|
nullable: isNullable,
|
|
@@ -479,17 +483,19 @@ const printerZod = ast.definePrinter((options) => {
|
|
|
479
483
|
if (hasSelfRef) return `get "${propName}"() { return ${value} }`;
|
|
480
484
|
return `"${propName}": ${value}`;
|
|
481
485
|
}).join(",\n ")}\n })`;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
486
|
+
return (() => {
|
|
487
|
+
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
488
|
+
const catchallType = this.transform(node.additionalProperties);
|
|
489
|
+
return catchallType ? `${objectBase}.catchall(${catchallType})` : objectBase;
|
|
490
|
+
}
|
|
491
|
+
if (node.additionalProperties === true) return `${objectBase}.catchall(${this.transform(ast.createSchema({ type: "unknown" }))})`;
|
|
492
|
+
if (node.additionalProperties === false) return `${objectBase}.strict()`;
|
|
493
|
+
return objectBase;
|
|
494
|
+
})();
|
|
488
495
|
},
|
|
489
496
|
array(node) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return result;
|
|
497
|
+
const base = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(ast.createSchema({ type: "unknown" }))})${lengthConstraints(node)}`;
|
|
498
|
+
return node.unique ? `${base}.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : base;
|
|
493
499
|
},
|
|
494
500
|
tuple(node) {
|
|
495
501
|
return `z.tuple([${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ")}])`;
|
|
@@ -510,47 +516,29 @@ const printerZod = ast.definePrinter((options) => {
|
|
|
510
516
|
if (members.length === 0) return "";
|
|
511
517
|
const [first, ...rest] = members;
|
|
512
518
|
if (!first) return "";
|
|
513
|
-
|
|
514
|
-
if (!
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
if (c) {
|
|
519
|
-
base += c;
|
|
520
|
-
continue;
|
|
521
|
-
}
|
|
522
|
-
} else if (member.primitive === "number" || member.primitive === "integer") {
|
|
523
|
-
const c = numberConstraints(ast.narrowSchema(member, "number") ?? ast.narrowSchema(member, "integer") ?? {});
|
|
524
|
-
if (c) {
|
|
525
|
-
base += c;
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
} else if (member.primitive === "array") {
|
|
529
|
-
const c = lengthConstraints(ast.narrowSchema(member, "array") ?? {});
|
|
530
|
-
if (c) {
|
|
531
|
-
base += c;
|
|
532
|
-
continue;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
519
|
+
const firstBase = this.transform(first);
|
|
520
|
+
if (!firstBase) return "";
|
|
521
|
+
return rest.reduce((acc, member) => {
|
|
522
|
+
const constraint = getMemberConstraint(member);
|
|
523
|
+
if (constraint) return acc + constraint;
|
|
535
524
|
const transformed = this.transform(member);
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
return base;
|
|
525
|
+
return transformed ? `${acc}.and(${transformed})` : acc;
|
|
526
|
+
}, firstBase);
|
|
539
527
|
},
|
|
540
528
|
...options.nodes
|
|
541
529
|
},
|
|
542
530
|
print(node) {
|
|
543
531
|
const { keysToOmit } = this.options;
|
|
544
|
-
|
|
545
|
-
if (!
|
|
532
|
+
const transformed = this.transform(node);
|
|
533
|
+
if (!transformed) return null;
|
|
546
534
|
const meta = ast.syncSchemaRef(node);
|
|
547
|
-
if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) {
|
|
548
|
-
const lazyMatch = base.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
549
|
-
if (lazyMatch) base = `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
550
|
-
else base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
551
|
-
}
|
|
552
535
|
return applyModifiers({
|
|
553
|
-
value:
|
|
536
|
+
value: (() => {
|
|
537
|
+
if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
|
|
538
|
+
const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
539
|
+
if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
540
|
+
return `${transformed}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
541
|
+
})(),
|
|
554
542
|
nullable: meta.nullable,
|
|
555
543
|
optional: meta.optional,
|
|
556
544
|
nullish: meta.nullish,
|
|
@@ -566,6 +554,11 @@ function strictOneOfMember(member, node) {
|
|
|
566
554
|
if (node.type === "object" && (node.additionalProperties === void 0 || node.additionalProperties === false)) return member.replace(/^z\.object\(/, "z.strictObject(");
|
|
567
555
|
return member;
|
|
568
556
|
}
|
|
557
|
+
function getMemberConstraintMini(member) {
|
|
558
|
+
if (member.primitive === "string") return lengthChecksMini(ast.narrowSchema(member, "string") ?? {}) || void 0;
|
|
559
|
+
if (member.primitive === "number" || member.primitive === "integer") return numberChecksMini(ast.narrowSchema(member, "number") ?? ast.narrowSchema(member, "integer") ?? {}) || void 0;
|
|
560
|
+
if (member.primitive === "array") return lengthChecksMini(ast.narrowSchema(member, "array") ?? {}) || void 0;
|
|
561
|
+
}
|
|
569
562
|
/**
|
|
570
563
|
* Zod v4 **Mini** printer built with `definePrinter`.
|
|
571
564
|
*
|
|
@@ -634,7 +627,7 @@ const printerZodMini = ast.definePrinter((options) => {
|
|
|
634
627
|
return `z.enum([${nonNullValues.map(formatLiteral).join(", ")}])`;
|
|
635
628
|
},
|
|
636
629
|
ref(node) {
|
|
637
|
-
if (!node.name) return
|
|
630
|
+
if (!node.name) return null;
|
|
638
631
|
const refName = node.ref ? ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
639
632
|
const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
|
|
640
633
|
if (node.ref && this.options.cyclicSchemas?.has(refName)) return `z.lazy(() => ${resolvedName})`;
|
|
@@ -648,9 +641,10 @@ const printerZodMini = ast.definePrinter((options) => {
|
|
|
648
641
|
const isOptional = schema.optional;
|
|
649
642
|
const isNullish = schema.nullish;
|
|
650
643
|
const hasSelfRef = this.options.cyclicSchemas != null && ast.containsCircularRef(schema, { circularSchemas: this.options.cyclicSchemas });
|
|
644
|
+
const savedCyclicSchemas = this.options.cyclicSchemas;
|
|
651
645
|
if (hasSelfRef) this.options.cyclicSchemas = void 0;
|
|
652
646
|
const baseOutput = this.transform(schema) ?? this.transform(ast.createSchema({ type: "unknown" }));
|
|
653
|
-
if (hasSelfRef) this.options.cyclicSchemas =
|
|
647
|
+
if (hasSelfRef) this.options.cyclicSchemas = savedCyclicSchemas;
|
|
654
648
|
const value = applyMiniModifiers({
|
|
655
649
|
value: this.options.wrapOutput ? this.options.wrapOutput({
|
|
656
650
|
output: baseOutput,
|
|
@@ -666,9 +660,8 @@ const printerZodMini = ast.definePrinter((options) => {
|
|
|
666
660
|
}).join(",\n ")}\n })`;
|
|
667
661
|
},
|
|
668
662
|
array(node) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
return result;
|
|
663
|
+
const base = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(ast.createSchema({ type: "unknown" }))})${lengthChecksMini(node)}`;
|
|
664
|
+
return node.unique ? `${base}.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : base;
|
|
672
665
|
},
|
|
673
666
|
tuple(node) {
|
|
674
667
|
return `z.tuple([${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ")}])`;
|
|
@@ -689,47 +682,29 @@ const printerZodMini = ast.definePrinter((options) => {
|
|
|
689
682
|
if (members.length === 0) return "";
|
|
690
683
|
const [first, ...rest] = members;
|
|
691
684
|
if (!first) return "";
|
|
692
|
-
|
|
693
|
-
if (!
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (c) {
|
|
698
|
-
base += c;
|
|
699
|
-
continue;
|
|
700
|
-
}
|
|
701
|
-
} else if (member.primitive === "number" || member.primitive === "integer") {
|
|
702
|
-
const c = numberChecksMini(ast.narrowSchema(member, "number") ?? ast.narrowSchema(member, "integer") ?? {});
|
|
703
|
-
if (c) {
|
|
704
|
-
base += c;
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
} else if (member.primitive === "array") {
|
|
708
|
-
const c = lengthChecksMini(ast.narrowSchema(member, "array") ?? {});
|
|
709
|
-
if (c) {
|
|
710
|
-
base += c;
|
|
711
|
-
continue;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
685
|
+
const firstBase = this.transform(first);
|
|
686
|
+
if (!firstBase) return "";
|
|
687
|
+
return rest.reduce((acc, member) => {
|
|
688
|
+
const constraint = getMemberConstraintMini(member);
|
|
689
|
+
if (constraint) return acc + constraint;
|
|
714
690
|
const transformed = this.transform(member);
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
return base;
|
|
691
|
+
return transformed ? `z.intersection(${acc}, ${transformed})` : acc;
|
|
692
|
+
}, firstBase);
|
|
718
693
|
},
|
|
719
694
|
...options.nodes
|
|
720
695
|
},
|
|
721
696
|
print(node) {
|
|
722
697
|
const { keysToOmit } = this.options;
|
|
723
|
-
|
|
724
|
-
if (!
|
|
698
|
+
const transformed = this.transform(node);
|
|
699
|
+
if (!transformed) return null;
|
|
725
700
|
const meta = ast.syncSchemaRef(node);
|
|
726
|
-
if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) {
|
|
727
|
-
const lazyMatch = base.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
728
|
-
if (lazyMatch) base = `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
729
|
-
else base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
730
|
-
}
|
|
731
701
|
return applyMiniModifiers({
|
|
732
|
-
value:
|
|
702
|
+
value: (() => {
|
|
703
|
+
if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
|
|
704
|
+
const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
705
|
+
if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
706
|
+
return `${transformed}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
707
|
+
})(),
|
|
733
708
|
nullable: meta.nullable,
|
|
734
709
|
optional: meta.optional,
|
|
735
710
|
nullish: meta.nullish,
|
|
@@ -740,9 +715,11 @@ const printerZodMini = ast.definePrinter((options) => {
|
|
|
740
715
|
});
|
|
741
716
|
//#endregion
|
|
742
717
|
//#region src/generators/zodGenerator.tsx
|
|
718
|
+
const zodPrinterCache = /* @__PURE__ */ new WeakMap();
|
|
719
|
+
const zodMiniPrinterCache = /* @__PURE__ */ new WeakMap();
|
|
743
720
|
const zodGenerator = defineGenerator({
|
|
744
721
|
name: "zod",
|
|
745
|
-
renderer:
|
|
722
|
+
renderer: jsxRendererSync,
|
|
746
723
|
schema(node, ctx) {
|
|
747
724
|
const { adapter, config, resolver, root } = ctx;
|
|
748
725
|
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options;
|
|
@@ -773,31 +750,53 @@ const zodGenerator = defineGenerator({
|
|
|
773
750
|
})
|
|
774
751
|
};
|
|
775
752
|
const inferTypeName = inferred ? resolver.resolveSchemaTypeName(node.name) : void 0;
|
|
776
|
-
const cyclicSchemas =
|
|
777
|
-
const schemaPrinter = mini ?
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
753
|
+
const cyclicSchemas = new Set(ctx.meta.circularNames);
|
|
754
|
+
const schemaPrinter = mini ? getCachedMiniPrinter() : getCachedStdPrinter();
|
|
755
|
+
function getCachedStdPrinter() {
|
|
756
|
+
const cached = zodPrinterCache.get(resolver);
|
|
757
|
+
if (cached && cached.coercion === coercion && cached.guidType === guidType && cached.dateType === dateType) return cached.printer;
|
|
758
|
+
const p = printerZod({
|
|
759
|
+
coercion,
|
|
760
|
+
guidType,
|
|
761
|
+
dateType,
|
|
762
|
+
wrapOutput,
|
|
763
|
+
resolver,
|
|
764
|
+
cyclicSchemas,
|
|
765
|
+
nodes: printer?.nodes
|
|
766
|
+
});
|
|
767
|
+
zodPrinterCache.set(resolver, {
|
|
768
|
+
printer: p,
|
|
769
|
+
coercion,
|
|
770
|
+
guidType,
|
|
771
|
+
dateType
|
|
772
|
+
});
|
|
773
|
+
return p;
|
|
774
|
+
}
|
|
775
|
+
function getCachedMiniPrinter() {
|
|
776
|
+
const cached = zodMiniPrinterCache.get(resolver);
|
|
777
|
+
if (cached && cached.guidType === guidType) return cached.printer;
|
|
778
|
+
const p = printerZodMini({
|
|
779
|
+
guidType,
|
|
780
|
+
wrapOutput,
|
|
781
|
+
resolver,
|
|
782
|
+
cyclicSchemas,
|
|
783
|
+
nodes: printer?.nodes
|
|
784
|
+
});
|
|
785
|
+
zodMiniPrinterCache.set(resolver, {
|
|
786
|
+
printer: p,
|
|
787
|
+
guidType
|
|
788
|
+
});
|
|
789
|
+
return p;
|
|
790
|
+
}
|
|
792
791
|
return /* @__PURE__ */ jsxs(File, {
|
|
793
792
|
baseName: meta.file.baseName,
|
|
794
793
|
path: meta.file.path,
|
|
795
794
|
meta: meta.file.meta,
|
|
796
|
-
banner: resolver.resolveBanner(
|
|
795
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
797
796
|
output,
|
|
798
797
|
config
|
|
799
798
|
}),
|
|
800
|
-
footer: resolver.resolveFooter(
|
|
799
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
801
800
|
output,
|
|
802
801
|
config
|
|
803
802
|
}),
|
|
@@ -838,7 +837,7 @@ const zodGenerator = defineGenerator({
|
|
|
838
837
|
output,
|
|
839
838
|
group
|
|
840
839
|
}) };
|
|
841
|
-
const cyclicSchemas =
|
|
840
|
+
const cyclicSchemas = new Set(ctx.meta.circularNames);
|
|
842
841
|
function renderSchemaEntry({ schema, name, keysToOmit }) {
|
|
843
842
|
if (!schema) return null;
|
|
844
843
|
const inferTypeName = inferred ? resolver.resolveTypeName(name) : void 0;
|
|
@@ -853,14 +852,22 @@ const zodGenerator = defineGenerator({
|
|
|
853
852
|
group
|
|
854
853
|
}).path
|
|
855
854
|
}));
|
|
856
|
-
const
|
|
855
|
+
const cachedStd = zodPrinterCache.get(resolver);
|
|
856
|
+
const cachedMini = zodMiniPrinterCache.get(resolver);
|
|
857
|
+
const schemaPrinter = mini ? keysToOmit?.length ? printerZodMini({
|
|
857
858
|
guidType,
|
|
858
859
|
wrapOutput,
|
|
859
860
|
resolver,
|
|
860
861
|
keysToOmit,
|
|
861
862
|
cyclicSchemas,
|
|
862
863
|
nodes: printer?.nodes
|
|
863
|
-
}) :
|
|
864
|
+
}) : cachedMini?.guidType === guidType ? cachedMini.printer : printerZodMini({
|
|
865
|
+
guidType,
|
|
866
|
+
wrapOutput,
|
|
867
|
+
resolver,
|
|
868
|
+
cyclicSchemas,
|
|
869
|
+
nodes: printer?.nodes
|
|
870
|
+
}) : keysToOmit?.length ? printerZod({
|
|
864
871
|
coercion,
|
|
865
872
|
guidType,
|
|
866
873
|
dateType,
|
|
@@ -869,6 +876,14 @@ const zodGenerator = defineGenerator({
|
|
|
869
876
|
keysToOmit,
|
|
870
877
|
cyclicSchemas,
|
|
871
878
|
nodes: printer?.nodes
|
|
879
|
+
}) : cachedStd?.coercion === coercion && cachedStd?.guidType === guidType && cachedStd?.dateType === dateType ? cachedStd.printer : printerZod({
|
|
880
|
+
coercion,
|
|
881
|
+
guidType,
|
|
882
|
+
dateType,
|
|
883
|
+
wrapOutput,
|
|
884
|
+
resolver,
|
|
885
|
+
cyclicSchemas,
|
|
886
|
+
nodes: printer?.nodes
|
|
872
887
|
});
|
|
873
888
|
return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
874
889
|
root: meta.file.path,
|
|
@@ -925,11 +940,11 @@ const zodGenerator = defineGenerator({
|
|
|
925
940
|
baseName: meta.file.baseName,
|
|
926
941
|
path: meta.file.path,
|
|
927
942
|
meta: meta.file.meta,
|
|
928
|
-
banner: resolver.resolveBanner(
|
|
943
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
929
944
|
output,
|
|
930
945
|
config
|
|
931
946
|
}),
|
|
932
|
-
footer: resolver.resolveFooter(
|
|
947
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
933
948
|
output,
|
|
934
949
|
config
|
|
935
950
|
}),
|
|
@@ -947,7 +962,7 @@ const zodGenerator = defineGenerator({
|
|
|
947
962
|
});
|
|
948
963
|
},
|
|
949
964
|
operations(nodes, ctx) {
|
|
950
|
-
const {
|
|
965
|
+
const { config, resolver, root } = ctx;
|
|
951
966
|
const { output, importPath, group, operations, paramsCasing } = ctx.options;
|
|
952
967
|
if (!operations) return;
|
|
953
968
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -994,11 +1009,11 @@ const zodGenerator = defineGenerator({
|
|
|
994
1009
|
baseName: meta.file.baseName,
|
|
995
1010
|
path: meta.file.path,
|
|
996
1011
|
meta: meta.file.meta,
|
|
997
|
-
banner: resolver.resolveBanner(
|
|
1012
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
998
1013
|
output,
|
|
999
1014
|
config
|
|
1000
1015
|
}),
|
|
1001
|
-
footer: resolver.resolveFooter(
|
|
1016
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
1002
1017
|
output,
|
|
1003
1018
|
config
|
|
1004
1019
|
}),
|