attaform 0.16.4 → 0.17.1
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 +4 -2
- package/dist/chunks/devtools.cjs +19 -12
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +19 -12
- package/dist/chunks/devtools.mjs.map +1 -1
- package/dist/chunks/indexeddb.cjs +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/session-storage.cjs +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/index.cjs +26 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -9
- package/dist/index.d.mts +52 -9
- package/dist/index.d.ts +52 -9
- package/dist/index.mjs +28 -9
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/runtime/plugins/attaform.cjs +3 -3
- package/dist/runtime/plugins/attaform.cjs.map +1 -1
- package/dist/runtime/plugins/attaform.mjs +3 -3
- package/dist/runtime/plugins/attaform.mjs.map +1 -1
- package/dist/shared/{attaform.CMRmwGDt.d.cts → attaform.B1jvxsOF.d.mts} +1 -1
- package/dist/shared/{attaform.DyV1O4tI.mjs → attaform.B3ZaPIzS.mjs} +1436 -391
- package/dist/shared/attaform.B3ZaPIzS.mjs.map +1 -0
- package/dist/shared/{attaform.Dd_pWnmn.cjs → attaform.B5qiXQwN.cjs} +59 -10
- package/dist/shared/attaform.B5qiXQwN.cjs.map +1 -0
- package/dist/shared/{attaform.CIwZtbGV.cjs → attaform.BBM2muQ9.cjs} +2 -2
- package/dist/shared/{attaform.CIwZtbGV.cjs.map → attaform.BBM2muQ9.cjs.map} +1 -1
- package/dist/shared/{attaform.keLBaHB6.cjs → attaform.BV40t5y2.cjs} +240 -115
- package/dist/shared/attaform.BV40t5y2.cjs.map +1 -0
- package/dist/shared/attaform.C0iFnTN0.d.ts +165 -0
- package/dist/shared/{attaform.CXMOheyZ.d.mts → attaform.C6qzEdIM.d.cts} +1 -1
- package/dist/shared/{attaform.CJttVxRj.cjs → attaform.C8LVFVVe.cjs} +2 -2
- package/dist/shared/{attaform.CJttVxRj.cjs.map → attaform.C8LVFVVe.cjs.map} +1 -1
- package/dist/shared/attaform.CHorcsIU.d.cts +165 -0
- package/dist/shared/{attaform.BfMxsfmE.mjs → attaform.CIEQgJnM.mjs} +143 -78
- package/dist/shared/attaform.CIEQgJnM.mjs.map +1 -0
- package/dist/shared/{attaform.CCQkY4Ta.d.ts → attaform.CTwNcpLE.d.ts} +1 -1
- package/dist/shared/{attaform.UA19EF3J.mjs → attaform.CVCmBKZX.mjs} +59 -10
- package/dist/shared/attaform.CVCmBKZX.mjs.map +1 -0
- package/dist/shared/{attaform.CU3JperC.d.cts → attaform.C_5aB6EQ.d.cts} +657 -135
- package/dist/shared/{attaform.CU3JperC.d.mts → attaform.C_5aB6EQ.d.mts} +657 -135
- package/dist/shared/{attaform.CU3JperC.d.ts → attaform.C_5aB6EQ.d.ts} +657 -135
- package/dist/shared/{attaform.fegmBJaq.cjs → attaform.Cer8JO_P.cjs} +1435 -389
- package/dist/shared/attaform.Cer8JO_P.cjs.map +1 -0
- package/dist/shared/{attaform.g7rfuXdz.mjs → attaform.CpERWz3u.mjs} +240 -115
- package/dist/shared/attaform.CpERWz3u.mjs.map +1 -0
- package/dist/shared/attaform.CuE-bS1C.d.mts +165 -0
- package/dist/shared/{attaform.rIRYSUI1.cjs → attaform.Dee2rU1P.cjs} +145 -77
- package/dist/shared/attaform.Dee2rU1P.cjs.map +1 -0
- package/dist/shared/{attaform.CINUMjPq.mjs → attaform.Vo-Kft0t.mjs} +2 -2
- package/dist/shared/{attaform.CINUMjPq.mjs.map → attaform.Vo-Kft0t.mjs.map} +1 -1
- package/dist/shared/{attaform.DZRj9s0s.mjs → attaform.h1sq3BFu.mjs} +2 -2
- package/dist/shared/{attaform.DZRj9s0s.mjs.map → attaform.h1sq3BFu.mjs.map} +1 -1
- package/dist/zod-v3.cjs +3 -3
- package/dist/zod-v3.d.cts +27 -5
- package/dist/zod-v3.d.mts +27 -5
- package/dist/zod-v3.d.ts +27 -5
- package/dist/zod-v3.mjs +3 -3
- package/dist/zod-v4.cjs +3 -3
- package/dist/zod-v4.d.cts +16 -42
- package/dist/zod-v4.d.mts +16 -42
- package/dist/zod-v4.d.ts +16 -42
- package/dist/zod-v4.mjs +3 -3
- package/dist/zod.cjs +4 -4
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +7 -5
- package/dist/zod.d.mts +7 -5
- package/dist/zod.d.ts +7 -5
- package/dist/zod.mjs +5 -5
- package/dist/zod.mjs.map +1 -1
- package/package.json +6 -11
- package/dist/shared/attaform.BfMxsfmE.mjs.map +0 -1
- package/dist/shared/attaform.Dd_pWnmn.cjs.map +0 -1
- package/dist/shared/attaform.DyV1O4tI.mjs.map +0 -1
- package/dist/shared/attaform.UA19EF3J.mjs.map +0 -1
- package/dist/shared/attaform.fegmBJaq.cjs.map +0 -1
- package/dist/shared/attaform.g7rfuXdz.mjs.map +0 -1
- package/dist/shared/attaform.keLBaHB6.cjs.map +0 -1
- package/dist/shared/attaform.rIRYSUI1.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { g as getAtPath, s as slimKindOf, f as setAtPath, j as isPlainRecord, A as AttaformErrorCode, h as humanize, e as useAbstractForm } from './attaform.
|
|
2
|
-
import { a as AttaformError, _ as __DEV__, b as InvalidUseFormConfigError } from './attaform.
|
|
1
|
+
import { g as getAtPath, s as slimKindOf, f as setAtPath, j as isPlainRecord, A as AttaformErrorCode, h as humanize, e as useAbstractForm } from './attaform.B3ZaPIzS.mjs';
|
|
2
|
+
import { a as AttaformError, _ as __DEV__, b as InvalidUseFormConfigError } from './attaform.CIEQgJnM.mjs';
|
|
3
3
|
import { f as fieldMetaStore, g as getFieldMetaForSchema, a as getFieldMetaListForSchema } from './attaform.D13GMFgK.mjs';
|
|
4
|
-
import { c as canonicalizePath } from './attaform.
|
|
4
|
+
import { c as canonicalizePath } from './attaform.h1sq3BFu.mjs';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
const fieldMeta = fieldMetaStore;
|
|
@@ -115,6 +115,8 @@ function kindOf(schema) {
|
|
|
115
115
|
return "intersection";
|
|
116
116
|
case "catch":
|
|
117
117
|
return "catch";
|
|
118
|
+
case "transform":
|
|
119
|
+
return "transform";
|
|
118
120
|
case "promise":
|
|
119
121
|
return "promise";
|
|
120
122
|
case "custom":
|
|
@@ -172,6 +174,18 @@ function unwrapPipe(schema) {
|
|
|
172
174
|
const def = readDef(schema);
|
|
173
175
|
return def?.in ?? def?.out;
|
|
174
176
|
}
|
|
177
|
+
function unwrapPipeIn(schema) {
|
|
178
|
+
const def = readDef(schema);
|
|
179
|
+
return def?.in;
|
|
180
|
+
}
|
|
181
|
+
function unwrapPipeOut(schema) {
|
|
182
|
+
const def = readDef(schema);
|
|
183
|
+
return def?.out;
|
|
184
|
+
}
|
|
185
|
+
function readTransformFn(schema) {
|
|
186
|
+
const def = readDef(schema);
|
|
187
|
+
return typeof def?.transform === "function" ? def.transform : void 0;
|
|
188
|
+
}
|
|
175
189
|
function unwrapLazy(schema) {
|
|
176
190
|
const def = readDef(schema);
|
|
177
191
|
const getter = def?.getter;
|
|
@@ -363,11 +377,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
363
377
|
}
|
|
364
378
|
case "lazy": {
|
|
365
379
|
const getter = getLazyGetter(schema);
|
|
366
|
-
if (getter !== void 0 && lazyGetters.includes(getter))
|
|
367
|
-
throw new UnsupportedSchemaError(
|
|
368
|
-
`[attaform/zod] Recursive z.lazy() at '${labelPath(path)}'`
|
|
369
|
-
);
|
|
370
|
-
}
|
|
380
|
+
if (getter !== void 0 && lazyGetters.includes(getter)) return;
|
|
371
381
|
const inner = unwrapLazy(schema);
|
|
372
382
|
if (inner !== void 0) {
|
|
373
383
|
assertSupportedKinds(
|
|
@@ -403,6 +413,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
403
413
|
case "promise":
|
|
404
414
|
case "custom":
|
|
405
415
|
case "template-literal":
|
|
416
|
+
case "transform":
|
|
406
417
|
return;
|
|
407
418
|
default: {
|
|
408
419
|
const _exhaustive = kind;
|
|
@@ -421,6 +432,15 @@ function unwrapToDiscriminatedUnion(schema) {
|
|
|
421
432
|
next = unwrapInner(current);
|
|
422
433
|
} else if (kind === "pipe") {
|
|
423
434
|
next = unwrapPipe(current);
|
|
435
|
+
} else if (kind === "intersection") {
|
|
436
|
+
const left = getIntersectionLeft(current);
|
|
437
|
+
const right = getIntersectionRight(current);
|
|
438
|
+
const leftDU = left !== void 0 ? unwrapToDiscriminatedUnion(left) : void 0;
|
|
439
|
+
const rightDU = right !== void 0 ? unwrapToDiscriminatedUnion(right) : void 0;
|
|
440
|
+
if (leftDU !== void 0 && rightDU !== void 0) {
|
|
441
|
+
return void 0;
|
|
442
|
+
}
|
|
443
|
+
return leftDU ?? rightDU;
|
|
424
444
|
}
|
|
425
445
|
if (next === void 0) return void 0;
|
|
426
446
|
current = next;
|
|
@@ -548,6 +568,7 @@ function computeFingerprint(schema, cache, inProgress) {
|
|
|
548
568
|
case "promise":
|
|
549
569
|
case "custom":
|
|
550
570
|
case "template-literal":
|
|
571
|
+
case "transform":
|
|
551
572
|
return `${kind}:*`;
|
|
552
573
|
default: {
|
|
553
574
|
const _ = kind;
|
|
@@ -629,12 +650,10 @@ const PERMISSIVE = /* @__PURE__ */ new Set([
|
|
|
629
650
|
"map",
|
|
630
651
|
"set"
|
|
631
652
|
]);
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
return walk(schema, 0);
|
|
653
|
+
function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
654
|
+
return walk(schema, 0, maxRecursionDepth);
|
|
635
655
|
}
|
|
636
|
-
function walk(schema,
|
|
637
|
-
if (depth > MAX_LAZY_DEPTH) return new Set(PERMISSIVE);
|
|
656
|
+
function walk(schema, lazyDepth, maxDepth) {
|
|
638
657
|
const kind = kindOf(schema);
|
|
639
658
|
switch (kind) {
|
|
640
659
|
case "string":
|
|
@@ -678,13 +697,13 @@ function walk(schema, depth) {
|
|
|
678
697
|
return /* @__PURE__ */ new Set(["set"]);
|
|
679
698
|
case "optional": {
|
|
680
699
|
const inner = unwrapInner(schema);
|
|
681
|
-
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner,
|
|
700
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, lazyDepth, maxDepth);
|
|
682
701
|
innerSet.add("undefined");
|
|
683
702
|
return innerSet;
|
|
684
703
|
}
|
|
685
704
|
case "nullable": {
|
|
686
705
|
const inner = unwrapInner(schema);
|
|
687
|
-
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner,
|
|
706
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, lazyDepth, maxDepth);
|
|
688
707
|
innerSet.add("null");
|
|
689
708
|
return innerSet;
|
|
690
709
|
}
|
|
@@ -692,30 +711,31 @@ function walk(schema, depth) {
|
|
|
692
711
|
case "readonly":
|
|
693
712
|
case "catch": {
|
|
694
713
|
const inner = unwrapInner(schema);
|
|
695
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
714
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth, maxDepth);
|
|
696
715
|
}
|
|
697
716
|
case "pipe": {
|
|
698
717
|
const inner = unwrapPipe(schema);
|
|
699
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
718
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth, maxDepth);
|
|
700
719
|
}
|
|
701
720
|
case "lazy": {
|
|
721
|
+
if (lazyDepth >= maxDepth) return new Set(PERMISSIVE);
|
|
702
722
|
const inner = unwrapLazy(schema);
|
|
703
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
723
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth + 1, maxDepth);
|
|
704
724
|
}
|
|
705
725
|
case "union":
|
|
706
726
|
case "discriminated-union": {
|
|
707
727
|
const options = getUnionOptions(schema);
|
|
708
728
|
const out = /* @__PURE__ */ new Set();
|
|
709
729
|
for (const opt of options) {
|
|
710
|
-
for (const k of walk(opt,
|
|
730
|
+
for (const k of walk(opt, lazyDepth, maxDepth)) out.add(k);
|
|
711
731
|
}
|
|
712
732
|
return out.size === 0 ? new Set(PERMISSIVE) : out;
|
|
713
733
|
}
|
|
714
734
|
case "intersection": {
|
|
715
735
|
const left = getIntersectionLeft(schema);
|
|
716
736
|
const right = getIntersectionRight(schema);
|
|
717
|
-
const leftSet = left === void 0 ? new Set(PERMISSIVE) : walk(left,
|
|
718
|
-
const rightSet = right === void 0 ? new Set(PERMISSIVE) : walk(right,
|
|
737
|
+
const leftSet = left === void 0 ? new Set(PERMISSIVE) : walk(left, lazyDepth, maxDepth);
|
|
738
|
+
const rightSet = right === void 0 ? new Set(PERMISSIVE) : walk(right, lazyDepth, maxDepth);
|
|
719
739
|
const out = /* @__PURE__ */ new Set();
|
|
720
740
|
for (const k of leftSet) if (rightSet.has(k)) out.add(k);
|
|
721
741
|
return out;
|
|
@@ -731,6 +751,8 @@ function walk(schema, depth) {
|
|
|
731
751
|
case "promise":
|
|
732
752
|
case "custom":
|
|
733
753
|
case "template-literal":
|
|
754
|
+
case "transform":
|
|
755
|
+
return new Set(PERMISSIVE);
|
|
734
756
|
default:
|
|
735
757
|
return new Set(PERMISSIVE);
|
|
736
758
|
}
|
|
@@ -764,13 +786,13 @@ function slimKindOfRaw(value) {
|
|
|
764
786
|
}
|
|
765
787
|
|
|
766
788
|
const PATH_SEPARATOR$1 = ".";
|
|
767
|
-
function getNestedZodSchemasAtPath(schema, path) {
|
|
768
|
-
if (Array.isArray(path)) return walkSegments(schema, path.map(String));
|
|
789
|
+
function getNestedZodSchemasAtPath(schema, path, maxRecursionDepth) {
|
|
790
|
+
if (Array.isArray(path)) return walkSegments(schema, path.map(String), maxRecursionDepth, 0);
|
|
769
791
|
const pathString = path;
|
|
770
792
|
if (pathString.length === 0) return [schema];
|
|
771
|
-
return walkSegments(schema, pathString.split(PATH_SEPARATOR$1));
|
|
793
|
+
return walkSegments(schema, pathString.split(PATH_SEPARATOR$1), maxRecursionDepth, 0);
|
|
772
794
|
}
|
|
773
|
-
function walkSegments(schema, segments) {
|
|
795
|
+
function walkSegments(schema, segments, maxDepth, lazyDepth) {
|
|
774
796
|
if (segments.length === 0) return [schema];
|
|
775
797
|
const [head, ...rest] = segments;
|
|
776
798
|
if (head === void 0) return [schema];
|
|
@@ -780,23 +802,25 @@ function walkSegments(schema, segments) {
|
|
|
780
802
|
const shape = getObjectShape(schema);
|
|
781
803
|
if (!Object.hasOwn(shape, head)) return [];
|
|
782
804
|
const next = shape[head];
|
|
783
|
-
return next === void 0 ? [] : walkSegments(next, rest);
|
|
805
|
+
return next === void 0 ? [] : walkSegments(next, rest, maxDepth, lazyDepth);
|
|
784
806
|
}
|
|
785
807
|
case "array":
|
|
786
|
-
return walkSegments(getArrayElement(schema), rest);
|
|
808
|
+
return walkSegments(getArrayElement(schema), rest, maxDepth, lazyDepth);
|
|
787
809
|
case "set":
|
|
788
|
-
return walkSegments(getSetValueType(schema), rest);
|
|
810
|
+
return walkSegments(getSetValueType(schema), rest, maxDepth, lazyDepth);
|
|
789
811
|
case "record":
|
|
790
|
-
return walkSegments(getRecordValueType(schema), rest);
|
|
812
|
+
return walkSegments(getRecordValueType(schema), rest, maxDepth, lazyDepth);
|
|
791
813
|
case "tuple": {
|
|
792
814
|
const index = Number(head);
|
|
793
815
|
if (!Number.isInteger(index)) return [];
|
|
794
816
|
const items = getTupleItems(schema);
|
|
795
817
|
const item = items[index];
|
|
796
|
-
return item === void 0 ? [] : walkSegments(item, rest);
|
|
818
|
+
return item === void 0 ? [] : walkSegments(item, rest, maxDepth, lazyDepth);
|
|
797
819
|
}
|
|
798
820
|
case "union":
|
|
799
|
-
return getUnionOptions(schema).flatMap(
|
|
821
|
+
return getUnionOptions(schema).flatMap(
|
|
822
|
+
(opt) => walkSegments(opt, segments, maxDepth, lazyDepth)
|
|
823
|
+
);
|
|
800
824
|
case "discriminated-union": {
|
|
801
825
|
const options = getDiscriminatedOptions(schema);
|
|
802
826
|
const matching = options.filter((opt) => {
|
|
@@ -804,7 +828,7 @@ function walkSegments(schema, segments) {
|
|
|
804
828
|
return Object.hasOwn(shape, head);
|
|
805
829
|
});
|
|
806
830
|
const candidates = matching.length > 0 ? matching : options;
|
|
807
|
-
return candidates.flatMap((opt) => walkSegments(opt, segments));
|
|
831
|
+
return candidates.flatMap((opt) => walkSegments(opt, segments, maxDepth, lazyDepth));
|
|
808
832
|
}
|
|
809
833
|
case "optional":
|
|
810
834
|
case "nullable":
|
|
@@ -812,21 +836,22 @@ function walkSegments(schema, segments) {
|
|
|
812
836
|
case "readonly":
|
|
813
837
|
case "catch": {
|
|
814
838
|
const inner = unwrapInner(schema);
|
|
815
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
839
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth);
|
|
816
840
|
}
|
|
817
841
|
case "pipe": {
|
|
818
842
|
const inner = unwrapPipe(schema);
|
|
819
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
843
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth);
|
|
820
844
|
}
|
|
821
845
|
case "lazy": {
|
|
846
|
+
if (lazyDepth >= maxDepth) return [];
|
|
822
847
|
const inner = unwrapLazy(schema);
|
|
823
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
848
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth + 1);
|
|
824
849
|
}
|
|
825
850
|
case "intersection": {
|
|
826
851
|
const left = getIntersectionLeft(schema);
|
|
827
852
|
const right = getIntersectionRight(schema);
|
|
828
|
-
const leftResults = left === void 0 ? [] : walkSegments(left, segments);
|
|
829
|
-
const rightResults = right === void 0 ? [] : walkSegments(right, segments);
|
|
853
|
+
const leftResults = left === void 0 ? [] : walkSegments(left, segments, maxDepth, lazyDepth);
|
|
854
|
+
const rightResults = right === void 0 ? [] : walkSegments(right, segments, maxDepth, lazyDepth);
|
|
830
855
|
return [...leftResults, ...rightResults];
|
|
831
856
|
}
|
|
832
857
|
// Leaf types — can't descend further.
|
|
@@ -847,6 +872,7 @@ function walkSegments(schema, segments) {
|
|
|
847
872
|
case "promise":
|
|
848
873
|
case "custom":
|
|
849
874
|
case "template-literal":
|
|
875
|
+
case "transform":
|
|
850
876
|
return [];
|
|
851
877
|
default: {
|
|
852
878
|
const _exhaustive = kind;
|
|
@@ -958,6 +984,7 @@ function stripRefinements(schema) {
|
|
|
958
984
|
case "promise":
|
|
959
985
|
case "custom":
|
|
960
986
|
case "template-literal":
|
|
987
|
+
case "transform":
|
|
961
988
|
return schema;
|
|
962
989
|
default: {
|
|
963
990
|
const _exhaustive = kind;
|
|
@@ -1081,6 +1108,7 @@ function stripAsyncChecks(schema) {
|
|
|
1081
1108
|
case "promise":
|
|
1082
1109
|
case "custom":
|
|
1083
1110
|
case "template-literal":
|
|
1111
|
+
case "transform":
|
|
1084
1112
|
return s;
|
|
1085
1113
|
default: {
|
|
1086
1114
|
const _exhaustive = kind;
|
|
@@ -1090,34 +1118,39 @@ function stripAsyncChecks(schema) {
|
|
|
1090
1118
|
}
|
|
1091
1119
|
return recurse(schema);
|
|
1092
1120
|
}
|
|
1093
|
-
function getSlimSchema(schema, stripConfig) {
|
|
1121
|
+
function getSlimSchema(schema, stripConfig, maxRecursionDepth) {
|
|
1122
|
+
return walkSlim(schema, stripConfig, maxRecursionDepth, 0);
|
|
1123
|
+
}
|
|
1124
|
+
function walkSlim(schema, stripConfig, maxDepth, lazyDepth) {
|
|
1094
1125
|
const kind = kindOf(schema);
|
|
1095
1126
|
switch (kind) {
|
|
1096
1127
|
case "optional": {
|
|
1097
1128
|
const inner = unwrapInner(schema) ?? schema;
|
|
1098
|
-
const slimmedInner =
|
|
1129
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1099
1130
|
return stripConfig.stripOptional === true ? slimmedInner : slimmedInner.optional();
|
|
1100
1131
|
}
|
|
1101
1132
|
case "nullable": {
|
|
1102
1133
|
const inner = unwrapInner(schema) ?? schema;
|
|
1103
|
-
const slimmedInner =
|
|
1134
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1104
1135
|
return stripConfig.stripNullable === true ? slimmedInner : slimmedInner.nullable();
|
|
1105
1136
|
}
|
|
1106
1137
|
case "default": {
|
|
1107
1138
|
const inner = unwrapInner(schema) ?? schema;
|
|
1108
|
-
const slimmedInner =
|
|
1139
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1109
1140
|
if (stripConfig.stripDefaultValues === true) return slimmedInner;
|
|
1110
1141
|
const defaultValue = getDefaultValue(schema);
|
|
1111
1142
|
return slimmedInner.default(defaultValue);
|
|
1112
1143
|
}
|
|
1113
1144
|
case "readonly": {
|
|
1114
1145
|
const inner = unwrapInner(schema);
|
|
1115
|
-
return inner === void 0 ? schema :
|
|
1146
|
+
return inner === void 0 ? schema : walkSlim(inner, stripConfig, maxDepth, lazyDepth).readonly();
|
|
1116
1147
|
}
|
|
1117
1148
|
case "pipe": {
|
|
1118
1149
|
if (stripConfig.stripPipe === true) {
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1150
|
+
const pipeIn = unwrapPipeIn(schema);
|
|
1151
|
+
const pipeOut = unwrapPipeOut(schema);
|
|
1152
|
+
const real = pipeIn !== void 0 && kindOf(pipeIn) !== "transform" ? pipeIn : pipeOut !== void 0 && kindOf(pipeOut) !== "transform" ? pipeOut : pipeIn ?? pipeOut ?? schema;
|
|
1153
|
+
return walkSlim(real, stripConfig, maxDepth, lazyDepth);
|
|
1121
1154
|
}
|
|
1122
1155
|
return schema;
|
|
1123
1156
|
}
|
|
@@ -1125,20 +1158,30 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1125
1158
|
const shape = getObjectShape(schema);
|
|
1126
1159
|
const next = {};
|
|
1127
1160
|
for (const [k, v] of Object.entries(shape)) {
|
|
1128
|
-
next[k] =
|
|
1161
|
+
next[k] = walkSlim(v, stripConfig, maxDepth, lazyDepth);
|
|
1129
1162
|
}
|
|
1130
1163
|
return carryChecks(z.object(next), schema, stripConfig);
|
|
1131
1164
|
}
|
|
1132
1165
|
case "array": {
|
|
1133
1166
|
const element = getArrayElement(schema);
|
|
1134
|
-
return carryChecks(
|
|
1167
|
+
return carryChecks(
|
|
1168
|
+
z.array(walkSlim(element, stripConfig, maxDepth, lazyDepth)),
|
|
1169
|
+
schema,
|
|
1170
|
+
stripConfig
|
|
1171
|
+
);
|
|
1135
1172
|
}
|
|
1136
1173
|
case "set": {
|
|
1137
1174
|
const valueType = getSetValueType(schema);
|
|
1138
|
-
return carryChecks(
|
|
1175
|
+
return carryChecks(
|
|
1176
|
+
z.set(walkSlim(valueType, stripConfig, maxDepth, lazyDepth)),
|
|
1177
|
+
schema,
|
|
1178
|
+
stripConfig
|
|
1179
|
+
);
|
|
1139
1180
|
}
|
|
1140
1181
|
case "tuple": {
|
|
1141
|
-
const items = getTupleItems(schema).map(
|
|
1182
|
+
const items = getTupleItems(schema).map(
|
|
1183
|
+
(it) => walkSlim(it, stripConfig, maxDepth, lazyDepth)
|
|
1184
|
+
);
|
|
1142
1185
|
const rebuilt = z.tuple(
|
|
1143
1186
|
items
|
|
1144
1187
|
);
|
|
@@ -1146,18 +1189,20 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1146
1189
|
}
|
|
1147
1190
|
case "record": {
|
|
1148
1191
|
const keyType = getRecordKeyType(schema);
|
|
1149
|
-
const valueType =
|
|
1192
|
+
const valueType = walkSlim(getRecordValueType(schema), stripConfig, maxDepth, lazyDepth);
|
|
1150
1193
|
const rebuilt = z.record(keyType, valueType);
|
|
1151
1194
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1152
1195
|
}
|
|
1153
1196
|
case "union": {
|
|
1154
|
-
const options = getUnionOptions(schema).map(
|
|
1197
|
+
const options = getUnionOptions(schema).map(
|
|
1198
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1199
|
+
);
|
|
1155
1200
|
const rebuilt = z.union(options);
|
|
1156
1201
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1157
1202
|
}
|
|
1158
1203
|
case "discriminated-union": {
|
|
1159
1204
|
const options = getDiscriminatedOptions(schema).map(
|
|
1160
|
-
(opt) =>
|
|
1205
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1161
1206
|
);
|
|
1162
1207
|
const discriminator = getDiscriminator(schema);
|
|
1163
1208
|
if (discriminator === void 0) return schema;
|
|
@@ -1187,23 +1232,29 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1187
1232
|
case "template-literal":
|
|
1188
1233
|
return schema;
|
|
1189
1234
|
case "lazy": {
|
|
1235
|
+
if (lazyDepth >= maxDepth) return schema;
|
|
1190
1236
|
const inner = unwrapLazy(schema);
|
|
1191
1237
|
if (inner === void 0) return schema;
|
|
1192
|
-
const slimmedInner =
|
|
1238
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth + 1);
|
|
1193
1239
|
return z.lazy(() => slimmedInner);
|
|
1194
1240
|
}
|
|
1195
1241
|
case "intersection": {
|
|
1196
1242
|
const left = getIntersectionLeft(schema);
|
|
1197
1243
|
const right = getIntersectionRight(schema);
|
|
1198
1244
|
if (left === void 0 || right === void 0) return schema;
|
|
1199
|
-
return z.intersection(
|
|
1245
|
+
return z.intersection(
|
|
1246
|
+
walkSlim(left, stripConfig, maxDepth, lazyDepth),
|
|
1247
|
+
walkSlim(right, stripConfig, maxDepth, lazyDepth)
|
|
1248
|
+
);
|
|
1200
1249
|
}
|
|
1201
1250
|
case "catch": {
|
|
1202
1251
|
const inner = unwrapInner(schema);
|
|
1203
1252
|
if (inner === void 0) return schema;
|
|
1204
|
-
const slimmedInner =
|
|
1253
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1205
1254
|
return slimmedInner.catch(getCatchDefault(schema));
|
|
1206
1255
|
}
|
|
1256
|
+
case "transform":
|
|
1257
|
+
return schema;
|
|
1207
1258
|
default: {
|
|
1208
1259
|
const _exhaustive = kind;
|
|
1209
1260
|
throw new Error(`getSlimSchema: unhandled ZodKind '${_exhaustive}'`);
|
|
@@ -1211,23 +1262,23 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1211
1262
|
}
|
|
1212
1263
|
}
|
|
1213
1264
|
|
|
1214
|
-
function deriveDefault(schema, useDefault) {
|
|
1215
|
-
return defaultForKind(kindOf(schema), schema, useDefault);
|
|
1265
|
+
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
1266
|
+
return defaultForKind(kindOf(schema), schema, useDefault, maxRecursionDepth, 0);
|
|
1216
1267
|
}
|
|
1217
|
-
function defaultForKind(kind, schema, useDefault) {
|
|
1268
|
+
function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
1218
1269
|
switch (kind) {
|
|
1219
1270
|
case "object": {
|
|
1220
1271
|
const shape = getObjectShape(schema);
|
|
1221
1272
|
const out = {};
|
|
1222
1273
|
for (const [key, subSchema] of Object.entries(shape)) {
|
|
1223
|
-
out[key] =
|
|
1274
|
+
out[key] = defaultForKind(kindOf(subSchema), subSchema, useDefault, maxDepth, lazyDepth);
|
|
1224
1275
|
}
|
|
1225
1276
|
return out;
|
|
1226
1277
|
}
|
|
1227
1278
|
case "default": {
|
|
1228
1279
|
if (useDefault) return getDefaultValue(schema);
|
|
1229
1280
|
const inner = unwrapInner(schema);
|
|
1230
|
-
return inner === void 0 ? void 0 :
|
|
1281
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1231
1282
|
}
|
|
1232
1283
|
case "optional":
|
|
1233
1284
|
return void 0;
|
|
@@ -1235,11 +1286,13 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1235
1286
|
return null;
|
|
1236
1287
|
case "readonly": {
|
|
1237
1288
|
const inner = unwrapInner(schema);
|
|
1238
|
-
return inner === void 0 ? void 0 :
|
|
1289
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1239
1290
|
}
|
|
1240
1291
|
case "pipe": {
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1292
|
+
const out = unwrapPipeOut(schema);
|
|
1293
|
+
const inn = unwrapPipeIn(schema);
|
|
1294
|
+
const real = inn !== void 0 && kindOf(inn) !== "transform" ? inn : out !== void 0 && kindOf(out) !== "transform" ? out : inn ?? out;
|
|
1295
|
+
return real === void 0 ? void 0 : defaultForKind(kindOf(real), real, useDefault, maxDepth, lazyDepth);
|
|
1243
1296
|
}
|
|
1244
1297
|
case "array":
|
|
1245
1298
|
return [];
|
|
@@ -1249,16 +1302,18 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1249
1302
|
return {};
|
|
1250
1303
|
case "tuple": {
|
|
1251
1304
|
const items = getTupleItems(schema);
|
|
1252
|
-
return items.map(
|
|
1305
|
+
return items.map(
|
|
1306
|
+
(item) => defaultForKind(kindOf(item), item, useDefault, maxDepth, lazyDepth)
|
|
1307
|
+
);
|
|
1253
1308
|
}
|
|
1254
1309
|
case "union": {
|
|
1255
1310
|
const options = getUnionOptions(schema);
|
|
1256
1311
|
const first = options[0];
|
|
1257
|
-
return first === void 0 ? void 0 :
|
|
1312
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1258
1313
|
}
|
|
1259
1314
|
case "discriminated-union": {
|
|
1260
1315
|
const first = getDiscriminatedUnionFirstOption(schema);
|
|
1261
|
-
return first === void 0 ? void 0 :
|
|
1316
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1262
1317
|
}
|
|
1263
1318
|
case "string":
|
|
1264
1319
|
return "";
|
|
@@ -1285,20 +1340,21 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1285
1340
|
case "nan":
|
|
1286
1341
|
return NaN;
|
|
1287
1342
|
case "lazy": {
|
|
1343
|
+
if (lazyDepth >= maxDepth) return void 0;
|
|
1288
1344
|
const inner = unwrapLazy(schema);
|
|
1289
|
-
return inner === void 0 ? void 0 :
|
|
1345
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth + 1);
|
|
1290
1346
|
}
|
|
1291
1347
|
case "intersection": {
|
|
1292
1348
|
const left = getIntersectionLeft(schema);
|
|
1293
1349
|
const right = getIntersectionRight(schema);
|
|
1294
|
-
const l = left === void 0 ? void 0 :
|
|
1295
|
-
const r = right === void 0 ? void 0 :
|
|
1350
|
+
const l = left === void 0 ? void 0 : defaultForKind(kindOf(left), left, useDefault, maxDepth, lazyDepth);
|
|
1351
|
+
const r = right === void 0 ? void 0 : defaultForKind(kindOf(right), right, useDefault, maxDepth, lazyDepth);
|
|
1296
1352
|
return mergeDeep(l, r);
|
|
1297
1353
|
}
|
|
1298
1354
|
case "catch": {
|
|
1299
1355
|
if (useDefault) return getCatchDefault(schema);
|
|
1300
1356
|
const inner = unwrapInner(schema);
|
|
1301
|
-
return inner === void 0 ? void 0 :
|
|
1357
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1302
1358
|
}
|
|
1303
1359
|
case "any":
|
|
1304
1360
|
case "unknown":
|
|
@@ -1307,6 +1363,7 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1307
1363
|
case "promise":
|
|
1308
1364
|
case "custom":
|
|
1309
1365
|
case "template-literal":
|
|
1366
|
+
case "transform":
|
|
1310
1367
|
return void 0;
|
|
1311
1368
|
default: {
|
|
1312
1369
|
const _exhaustive = kind;
|
|
@@ -1331,14 +1388,18 @@ function mergeDeep(base, override) {
|
|
|
1331
1388
|
return result;
|
|
1332
1389
|
}
|
|
1333
1390
|
function getDefaultValuesFromZodSchema(opts) {
|
|
1334
|
-
const { schema, useDefaultSchemaValues, constraints } = opts;
|
|
1335
|
-
const initial = deriveDefault(schema, useDefaultSchemaValues);
|
|
1391
|
+
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
1392
|
+
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
1336
1393
|
const merged = mergeDeep(initial, constraints);
|
|
1337
|
-
const slimSchema = getSlimSchema(
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1394
|
+
const slimSchema = getSlimSchema(
|
|
1395
|
+
schema,
|
|
1396
|
+
{
|
|
1397
|
+
stripDefaultValues: true,
|
|
1398
|
+
stripPipe: true,
|
|
1399
|
+
stripRefinements: true
|
|
1400
|
+
},
|
|
1401
|
+
maxRecursionDepth
|
|
1402
|
+
);
|
|
1342
1403
|
const firstParse = slimSchema.safeParse(merged);
|
|
1343
1404
|
if (firstParse.success) {
|
|
1344
1405
|
return { data: firstParse.data, success: true, slimSchema };
|
|
@@ -1346,16 +1407,16 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1346
1407
|
let fixedData = merged;
|
|
1347
1408
|
for (const issue of firstParse.error.issues) {
|
|
1348
1409
|
const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
|
|
1349
|
-
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments);
|
|
1410
|
+
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments, maxRecursionDepth);
|
|
1350
1411
|
if (candidates.length === 0) continue;
|
|
1351
1412
|
const candidate = candidates[0];
|
|
1352
1413
|
if (candidate === void 0) continue;
|
|
1353
1414
|
const valueAtPath = getAtPath(merged, pathSegments);
|
|
1354
|
-
const slimKinds = slimPrimitivesOf(candidate);
|
|
1415
|
+
const slimKinds = slimPrimitivesOf(candidate, maxRecursionDepth);
|
|
1355
1416
|
if (slimKinds.size > 0 && slimKinds.has(slimKindOf(valueAtPath))) {
|
|
1356
1417
|
continue;
|
|
1357
1418
|
}
|
|
1358
|
-
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues);
|
|
1419
|
+
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1359
1420
|
if (fixValue === SKIP) continue;
|
|
1360
1421
|
fixedData = pathSegments.length === 0 ? fixValue : setAtPath(fixedData, pathSegments, fixValue);
|
|
1361
1422
|
}
|
|
@@ -1366,21 +1427,22 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1366
1427
|
return { data: fixedData, success: false, slimSchema };
|
|
1367
1428
|
}
|
|
1368
1429
|
const SKIP = Symbol("atta:skip-fix");
|
|
1369
|
-
function defaultFromIssue(issue, candidate, useDefaultSchemaValues) {
|
|
1430
|
+
function defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth) {
|
|
1370
1431
|
if (issue.code === "invalid_type") {
|
|
1371
1432
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
1372
1433
|
if (du !== void 0) {
|
|
1373
1434
|
const first = getDiscriminatedUnionFirstOption(du);
|
|
1374
|
-
if (first !== void 0)
|
|
1435
|
+
if (first !== void 0)
|
|
1436
|
+
return deriveDefault(first, useDefaultSchemaValues, maxRecursionDepth);
|
|
1375
1437
|
}
|
|
1376
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1438
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1377
1439
|
}
|
|
1378
1440
|
if (issue.code === "invalid_value") {
|
|
1379
1441
|
const values = issue.values;
|
|
1380
1442
|
if (values !== void 0 && values.length > 0) return values[0];
|
|
1381
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1443
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1382
1444
|
}
|
|
1383
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1445
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1384
1446
|
}
|
|
1385
1447
|
|
|
1386
1448
|
const PATH_SEPARATOR = ".";
|
|
@@ -1470,7 +1532,8 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
1470
1532
|
function zodV4Adapter(rootSchema) {
|
|
1471
1533
|
assertZodVersion(rootSchema);
|
|
1472
1534
|
assertSupportedKinds(rootSchema);
|
|
1473
|
-
return (formKey) => {
|
|
1535
|
+
return (formKey, options) => {
|
|
1536
|
+
const maxRecursionDepth = options.maxRecursionDepth;
|
|
1474
1537
|
const leafCache = /* @__PURE__ */ new Map();
|
|
1475
1538
|
let asyncValidationFlag = null;
|
|
1476
1539
|
return {
|
|
@@ -1483,13 +1546,16 @@ function zodV4Adapter(rootSchema) {
|
|
|
1483
1546
|
const { data } = getDefaultValuesFromZodSchema({
|
|
1484
1547
|
schema: rootSchema,
|
|
1485
1548
|
useDefaultSchemaValues: config.useDefaultSchemaValues,
|
|
1486
|
-
constraints: config.constraints
|
|
1549
|
+
constraints: config.constraints,
|
|
1550
|
+
maxRecursionDepth
|
|
1487
1551
|
});
|
|
1488
1552
|
if (config.strict !== false) {
|
|
1489
1553
|
try {
|
|
1490
|
-
const strictResult = rootSchema.safeParse(
|
|
1554
|
+
const strictResult = rootSchema.safeParse(
|
|
1555
|
+
data
|
|
1556
|
+
);
|
|
1491
1557
|
if (strictResult.success) {
|
|
1492
|
-
return { data
|
|
1558
|
+
return { data, errors: void 0, success: true, formKey };
|
|
1493
1559
|
}
|
|
1494
1560
|
return {
|
|
1495
1561
|
data,
|
|
@@ -1517,15 +1583,52 @@ function zodV4Adapter(rootSchema) {
|
|
|
1517
1583
|
}
|
|
1518
1584
|
return { data, errors: void 0, success: true, formKey };
|
|
1519
1585
|
},
|
|
1586
|
+
normalizeWriteValueAtPath(value, path) {
|
|
1587
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1588
|
+
const [first] = candidates;
|
|
1589
|
+
if (first === void 0) return value;
|
|
1590
|
+
let current = first;
|
|
1591
|
+
let result = value;
|
|
1592
|
+
for (let i = 0; i < 64; i++) {
|
|
1593
|
+
if (kindOf(current) !== "pipe") break;
|
|
1594
|
+
const pipeIn = unwrapPipeIn(current);
|
|
1595
|
+
if (pipeIn === void 0 || kindOf(pipeIn) !== "transform") break;
|
|
1596
|
+
const fn = readTransformFn(pipeIn);
|
|
1597
|
+
if (typeof fn !== "function") break;
|
|
1598
|
+
let next;
|
|
1599
|
+
try {
|
|
1600
|
+
next = fn(result);
|
|
1601
|
+
} catch (cause) {
|
|
1602
|
+
throw new Error(
|
|
1603
|
+
`[attaform] input normalization at path "${path.join(".")}" threw \u2014 write rejected.`,
|
|
1604
|
+
{ cause }
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1607
|
+
if (next instanceof Promise) {
|
|
1608
|
+
return value;
|
|
1609
|
+
}
|
|
1610
|
+
result = next;
|
|
1611
|
+
const out = unwrapPipeOut(current);
|
|
1612
|
+
if (out === void 0) break;
|
|
1613
|
+
current = out;
|
|
1614
|
+
}
|
|
1615
|
+
return result;
|
|
1616
|
+
},
|
|
1520
1617
|
getDefaultAtPath(path) {
|
|
1521
|
-
if (path.length === 0) return deriveDefault(rootSchema, true);
|
|
1522
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1618
|
+
if (path.length === 0) return deriveDefault(rootSchema, true, maxRecursionDepth);
|
|
1619
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1523
1620
|
if (first === void 0) return void 0;
|
|
1524
|
-
return deriveDefault(unwrapStructuralWrappers(first), true);
|
|
1621
|
+
return deriveDefault(unwrapStructuralWrappers(first), true, maxRecursionDepth);
|
|
1622
|
+
},
|
|
1623
|
+
getEmptyValueAtPath(path) {
|
|
1624
|
+
if (path.length === 0) return deriveDefault(rootSchema, false, maxRecursionDepth);
|
|
1625
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1626
|
+
if (first === void 0) return void 0;
|
|
1627
|
+
return deriveDefault(first, false, maxRecursionDepth);
|
|
1525
1628
|
},
|
|
1526
1629
|
arrayShapeAtPath(path) {
|
|
1527
1630
|
if (path.length === 0) return void 0;
|
|
1528
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1631
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1529
1632
|
if (first === void 0) return void 0;
|
|
1530
1633
|
const peeled = peelAllWrappers(first);
|
|
1531
1634
|
const kind = kindOf(peeled);
|
|
@@ -1534,13 +1637,13 @@ function zodV4Adapter(rootSchema) {
|
|
|
1534
1637
|
return void 0;
|
|
1535
1638
|
},
|
|
1536
1639
|
getSchemasAtPath(path) {
|
|
1537
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1640
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1538
1641
|
return resolved.map(
|
|
1539
1642
|
(schema) => ({
|
|
1540
1643
|
fingerprint: () => fingerprintZodSchema(schema),
|
|
1541
1644
|
needsAsyncValidation: () => containsAsyncRefine(schema),
|
|
1542
1645
|
getDefaultValues: () => ({
|
|
1543
|
-
data: deriveDefault(schema, true),
|
|
1646
|
+
data: deriveDefault(schema, true, maxRecursionDepth),
|
|
1544
1647
|
errors: void 0,
|
|
1545
1648
|
success: true,
|
|
1546
1649
|
formKey
|
|
@@ -1563,11 +1666,11 @@ function zodV4Adapter(rootSchema) {
|
|
|
1563
1666
|
},
|
|
1564
1667
|
getSlimPrimitiveTypesAtPath(path) {
|
|
1565
1668
|
if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
|
|
1566
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1669
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1567
1670
|
if (resolved.length === 0) return /* @__PURE__ */ new Set();
|
|
1568
1671
|
const out = /* @__PURE__ */ new Set();
|
|
1569
1672
|
for (const candidate of resolved) {
|
|
1570
|
-
for (const k of slimPrimitivesOf(candidate)) out.add(k);
|
|
1673
|
+
for (const k of slimPrimitivesOf(candidate, maxRecursionDepth)) out.add(k);
|
|
1571
1674
|
}
|
|
1572
1675
|
return out;
|
|
1573
1676
|
},
|
|
@@ -1582,15 +1685,15 @@ function zodV4Adapter(rootSchema) {
|
|
|
1582
1685
|
},
|
|
1583
1686
|
isRequiredAtPath(path) {
|
|
1584
1687
|
if (path.length === 0) return true;
|
|
1585
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1688
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1586
1689
|
if (resolved.length === 0) return false;
|
|
1587
1690
|
return resolved.every((candidate) => isLeafRequired(candidate));
|
|
1588
1691
|
},
|
|
1589
1692
|
getFieldMetaAtPath(path) {
|
|
1590
|
-
return resolveFieldMetaAtPath(rootSchema, path);
|
|
1693
|
+
return resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth);
|
|
1591
1694
|
},
|
|
1592
1695
|
getUnionDiscriminatorAtPath(path) {
|
|
1593
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1696
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1594
1697
|
let matchedUnion;
|
|
1595
1698
|
for (const candidate of candidates) {
|
|
1596
1699
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
@@ -1601,24 +1704,35 @@ function zodV4Adapter(rootSchema) {
|
|
|
1601
1704
|
if (matchedUnion === void 0) return void 0;
|
|
1602
1705
|
const discKey = getDiscriminator(matchedUnion);
|
|
1603
1706
|
if (discKey === void 0) return void 0;
|
|
1604
|
-
const
|
|
1707
|
+
const options2 = getDiscriminatedOptions(matchedUnion);
|
|
1708
|
+
const literalSet = /* @__PURE__ */ new Set();
|
|
1709
|
+
for (const opt of options2) {
|
|
1710
|
+
const shape = getObjectShape(opt);
|
|
1711
|
+
const litSchema = shape[discKey];
|
|
1712
|
+
if (litSchema === void 0) continue;
|
|
1713
|
+
if (kindOf(litSchema) !== "literal") continue;
|
|
1714
|
+
for (const v of getLiteralValues(litSchema)) literalSet.add(v);
|
|
1715
|
+
}
|
|
1605
1716
|
return {
|
|
1606
1717
|
discriminatorKey: discKey,
|
|
1607
1718
|
getVariantDefault(value) {
|
|
1608
|
-
for (const opt of
|
|
1719
|
+
for (const opt of options2) {
|
|
1609
1720
|
const shape = getObjectShape(opt);
|
|
1610
1721
|
const litSchema = shape[discKey];
|
|
1611
1722
|
if (litSchema === void 0) continue;
|
|
1612
1723
|
if (kindOf(litSchema) !== "literal") continue;
|
|
1613
1724
|
const literalValues = getLiteralValues(litSchema);
|
|
1614
|
-
if (literalValues.includes(value)) return deriveDefault(opt, true);
|
|
1725
|
+
if (literalValues.includes(value)) return deriveDefault(opt, true, maxRecursionDepth);
|
|
1615
1726
|
}
|
|
1616
1727
|
return void 0;
|
|
1728
|
+
},
|
|
1729
|
+
isVariantSelected(value) {
|
|
1730
|
+
return literalSet.has(value);
|
|
1617
1731
|
}
|
|
1618
1732
|
};
|
|
1619
1733
|
},
|
|
1620
|
-
validateAtPath(data, path,
|
|
1621
|
-
const trySync =
|
|
1734
|
+
validateAtPath(data, path, options2) {
|
|
1735
|
+
const trySync = options2?.sync === true;
|
|
1622
1736
|
if (trySync) {
|
|
1623
1737
|
try {
|
|
1624
1738
|
return runSync();
|
|
@@ -1636,13 +1750,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1636
1750
|
formKey
|
|
1637
1751
|
};
|
|
1638
1752
|
}
|
|
1639
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1753
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1640
1754
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1641
1755
|
const aggregated = [];
|
|
1642
1756
|
for (const candidate of resolved) {
|
|
1643
1757
|
const result = candidate.safeParse(data);
|
|
1644
1758
|
if (result.success) {
|
|
1645
|
-
return {
|
|
1759
|
+
return {
|
|
1760
|
+
data: result.data,
|
|
1761
|
+
errors: void 0,
|
|
1762
|
+
success: true,
|
|
1763
|
+
formKey
|
|
1764
|
+
};
|
|
1646
1765
|
}
|
|
1647
1766
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1648
1767
|
}
|
|
@@ -1650,7 +1769,9 @@ function zodV4Adapter(rootSchema) {
|
|
|
1650
1769
|
}
|
|
1651
1770
|
async function runAsync() {
|
|
1652
1771
|
if (path === void 0) {
|
|
1653
|
-
const result = await rootSchema.safeParseAsync(
|
|
1772
|
+
const result = await rootSchema.safeParseAsync(
|
|
1773
|
+
data
|
|
1774
|
+
);
|
|
1654
1775
|
return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
|
|
1655
1776
|
data: void 0,
|
|
1656
1777
|
errors: zodIssuesToValidationErrors(result.error.issues, formKey),
|
|
@@ -1658,13 +1779,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1658
1779
|
formKey
|
|
1659
1780
|
};
|
|
1660
1781
|
}
|
|
1661
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1782
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1662
1783
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1663
1784
|
const aggregated = [];
|
|
1664
1785
|
for (const candidate of resolved) {
|
|
1665
1786
|
const result = await candidate.safeParseAsync(data);
|
|
1666
1787
|
if (result.success) {
|
|
1667
|
-
return {
|
|
1788
|
+
return {
|
|
1789
|
+
data: result.data,
|
|
1790
|
+
errors: void 0,
|
|
1791
|
+
success: true,
|
|
1792
|
+
formKey
|
|
1793
|
+
};
|
|
1668
1794
|
}
|
|
1669
1795
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1670
1796
|
}
|
|
@@ -1842,6 +1968,7 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress)
|
|
|
1842
1968
|
case "promise":
|
|
1843
1969
|
case "custom":
|
|
1844
1970
|
case "template-literal":
|
|
1971
|
+
case "transform":
|
|
1845
1972
|
return;
|
|
1846
1973
|
}
|
|
1847
1974
|
} finally {
|
|
@@ -1856,9 +1983,9 @@ function consumePayload(schema, counters) {
|
|
|
1856
1983
|
counters.set(schema, idx + 1);
|
|
1857
1984
|
return payload;
|
|
1858
1985
|
}
|
|
1859
|
-
function resolveFieldMetaAtPath(rootSchema, path) {
|
|
1986
|
+
function resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth) {
|
|
1860
1987
|
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1861
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1988
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1862
1989
|
const target = candidates[0];
|
|
1863
1990
|
if (target === void 0) {
|
|
1864
1991
|
return {
|
|
@@ -1892,9 +2019,7 @@ function useForm(configuration) {
|
|
|
1892
2019
|
if (candidate === void 0 || candidate === null || candidate.schema === void 0) {
|
|
1893
2020
|
throw new InvalidUseFormConfigError();
|
|
1894
2021
|
}
|
|
1895
|
-
const adapter = zodV4Adapter(
|
|
1896
|
-
configuration.schema
|
|
1897
|
-
);
|
|
2022
|
+
const adapter = zodV4Adapter(configuration.schema);
|
|
1898
2023
|
return useAbstractForm({
|
|
1899
2024
|
...configuration,
|
|
1900
2025
|
schema: adapter
|
|
@@ -1902,4 +2027,4 @@ function useForm(configuration) {
|
|
|
1902
2027
|
}
|
|
1903
2028
|
|
|
1904
2029
|
export { UnsupportedSchemaError as U, assertZodVersion as a, fieldMeta as f, kindOf as k, useForm as u, withMeta as w, zodV4Adapter as z };
|
|
1905
|
-
//# sourceMappingURL=attaform.
|
|
2030
|
+
//# sourceMappingURL=attaform.CpERWz3u.mjs.map
|