attaform 0.16.4 → 0.17.0
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 +51 -8
- package/dist/index.d.mts +51 -8
- package/dist/index.d.ts +51 -8
- 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.Dd_pWnmn.cjs → attaform.0Wg7UEeX.cjs} +51 -10
- package/dist/shared/attaform.0Wg7UEeX.cjs.map +1 -0
- package/dist/shared/attaform.AOgGyRoI.d.cts +65 -0
- package/dist/shared/{attaform.CCQkY4Ta.d.ts → attaform.B0zue7zt.d.ts} +1 -1
- 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.fegmBJaq.cjs → attaform.BFumZXY2.cjs} +1422 -389
- package/dist/shared/attaform.BFumZXY2.cjs.map +1 -0
- package/dist/shared/attaform.BQ-iGGWd.d.mts +65 -0
- package/dist/shared/{attaform.DyV1O4tI.mjs → attaform.BT55rDNN.mjs} +1423 -391
- package/dist/shared/attaform.BT55rDNN.mjs.map +1 -0
- package/dist/shared/{attaform.CU3JperC.d.cts → attaform.BYbsV2Wv.d.cts} +574 -132
- package/dist/shared/{attaform.CU3JperC.d.mts → attaform.BYbsV2Wv.d.mts} +574 -132
- package/dist/shared/{attaform.CU3JperC.d.ts → attaform.BYbsV2Wv.d.ts} +574 -132
- package/dist/shared/{attaform.keLBaHB6.cjs → attaform.C6_zOf8x.cjs} +228 -113
- package/dist/shared/attaform.C6_zOf8x.cjs.map +1 -0
- 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.BfMxsfmE.mjs → attaform.CIEQgJnM.mjs} +143 -78
- package/dist/shared/attaform.CIEQgJnM.mjs.map +1 -0
- package/dist/shared/attaform.CX9v2M8k.d.ts +65 -0
- package/dist/shared/{attaform.g7rfuXdz.mjs → attaform.Cj0pCNVn.mjs} +228 -113
- package/dist/shared/attaform.Cj0pCNVn.mjs.map +1 -0
- package/dist/shared/{attaform.CMRmwGDt.d.cts → attaform.ClfCi1i2.d.mts} +1 -1
- package/dist/shared/{attaform.UA19EF3J.mjs → attaform.D6Q5ZP8L.mjs} +51 -10
- package/dist/shared/attaform.D6Q5ZP8L.mjs.map +1 -0
- package/dist/shared/{attaform.CXMOheyZ.d.mts → attaform.D7lomopc.d.cts} +1 -1
- 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 +5 -5
- package/dist/zod-v3.d.mts +5 -5
- package/dist/zod-v3.d.ts +5 -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 +6 -5
- package/dist/zod.d.mts +6 -5
- package/dist/zod.d.ts +6 -5
- package/dist/zod.mjs +5 -5
- package/dist/zod.mjs.map +1 -1
- package/package.json +3 -8
- 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,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const useFormContext = require('./attaform.
|
|
4
|
-
const plugin = require('./attaform.
|
|
3
|
+
const useFormContext = require('./attaform.BFumZXY2.cjs');
|
|
4
|
+
const plugin = require('./attaform.Dee2rU1P.cjs');
|
|
5
5
|
const fieldMetaStore = require('./attaform.C8CyvYa_.cjs');
|
|
6
|
-
const paths = require('./attaform.
|
|
6
|
+
const paths = require('./attaform.BBM2muQ9.cjs');
|
|
7
7
|
const zod = require('zod');
|
|
8
8
|
|
|
9
9
|
const fieldMeta = fieldMetaStore.fieldMetaStore;
|
|
@@ -117,6 +117,8 @@ function kindOf(schema) {
|
|
|
117
117
|
return "intersection";
|
|
118
118
|
case "catch":
|
|
119
119
|
return "catch";
|
|
120
|
+
case "transform":
|
|
121
|
+
return "transform";
|
|
120
122
|
case "promise":
|
|
121
123
|
return "promise";
|
|
122
124
|
case "custom":
|
|
@@ -174,6 +176,18 @@ function unwrapPipe(schema) {
|
|
|
174
176
|
const def = readDef(schema);
|
|
175
177
|
return def?.in ?? def?.out;
|
|
176
178
|
}
|
|
179
|
+
function unwrapPipeIn(schema) {
|
|
180
|
+
const def = readDef(schema);
|
|
181
|
+
return def?.in;
|
|
182
|
+
}
|
|
183
|
+
function unwrapPipeOut(schema) {
|
|
184
|
+
const def = readDef(schema);
|
|
185
|
+
return def?.out;
|
|
186
|
+
}
|
|
187
|
+
function readTransformFn(schema) {
|
|
188
|
+
const def = readDef(schema);
|
|
189
|
+
return typeof def?.transform === "function" ? def.transform : void 0;
|
|
190
|
+
}
|
|
177
191
|
function unwrapLazy(schema) {
|
|
178
192
|
const def = readDef(schema);
|
|
179
193
|
const getter = def?.getter;
|
|
@@ -365,11 +379,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
365
379
|
}
|
|
366
380
|
case "lazy": {
|
|
367
381
|
const getter = getLazyGetter(schema);
|
|
368
|
-
if (getter !== void 0 && lazyGetters.includes(getter))
|
|
369
|
-
throw new UnsupportedSchemaError(
|
|
370
|
-
`[attaform/zod] Recursive z.lazy() at '${labelPath(path)}'`
|
|
371
|
-
);
|
|
372
|
-
}
|
|
382
|
+
if (getter !== void 0 && lazyGetters.includes(getter)) return;
|
|
373
383
|
const inner = unwrapLazy(schema);
|
|
374
384
|
if (inner !== void 0) {
|
|
375
385
|
assertSupportedKinds(
|
|
@@ -405,6 +415,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
405
415
|
case "promise":
|
|
406
416
|
case "custom":
|
|
407
417
|
case "template-literal":
|
|
418
|
+
case "transform":
|
|
408
419
|
return;
|
|
409
420
|
default: {
|
|
410
421
|
const _exhaustive = kind;
|
|
@@ -423,6 +434,15 @@ function unwrapToDiscriminatedUnion(schema) {
|
|
|
423
434
|
next = unwrapInner(current);
|
|
424
435
|
} else if (kind === "pipe") {
|
|
425
436
|
next = unwrapPipe(current);
|
|
437
|
+
} else if (kind === "intersection") {
|
|
438
|
+
const left = getIntersectionLeft(current);
|
|
439
|
+
const right = getIntersectionRight(current);
|
|
440
|
+
const leftDU = left !== void 0 ? unwrapToDiscriminatedUnion(left) : void 0;
|
|
441
|
+
const rightDU = right !== void 0 ? unwrapToDiscriminatedUnion(right) : void 0;
|
|
442
|
+
if (leftDU !== void 0 && rightDU !== void 0) {
|
|
443
|
+
return void 0;
|
|
444
|
+
}
|
|
445
|
+
return leftDU ?? rightDU;
|
|
426
446
|
}
|
|
427
447
|
if (next === void 0) return void 0;
|
|
428
448
|
current = next;
|
|
@@ -550,6 +570,7 @@ function computeFingerprint(schema, cache, inProgress) {
|
|
|
550
570
|
case "promise":
|
|
551
571
|
case "custom":
|
|
552
572
|
case "template-literal":
|
|
573
|
+
case "transform":
|
|
553
574
|
return `${kind}:*`;
|
|
554
575
|
default: {
|
|
555
576
|
const _ = kind;
|
|
@@ -631,12 +652,10 @@ const PERMISSIVE = /* @__PURE__ */ new Set([
|
|
|
631
652
|
"map",
|
|
632
653
|
"set"
|
|
633
654
|
]);
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
return walk(schema, 0);
|
|
655
|
+
function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
656
|
+
return walk(schema, 0, maxRecursionDepth);
|
|
637
657
|
}
|
|
638
|
-
function walk(schema,
|
|
639
|
-
if (depth > MAX_LAZY_DEPTH) return new Set(PERMISSIVE);
|
|
658
|
+
function walk(schema, lazyDepth, maxDepth) {
|
|
640
659
|
const kind = kindOf(schema);
|
|
641
660
|
switch (kind) {
|
|
642
661
|
case "string":
|
|
@@ -680,13 +699,13 @@ function walk(schema, depth) {
|
|
|
680
699
|
return /* @__PURE__ */ new Set(["set"]);
|
|
681
700
|
case "optional": {
|
|
682
701
|
const inner = unwrapInner(schema);
|
|
683
|
-
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner,
|
|
702
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, lazyDepth, maxDepth);
|
|
684
703
|
innerSet.add("undefined");
|
|
685
704
|
return innerSet;
|
|
686
705
|
}
|
|
687
706
|
case "nullable": {
|
|
688
707
|
const inner = unwrapInner(schema);
|
|
689
|
-
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner,
|
|
708
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, lazyDepth, maxDepth);
|
|
690
709
|
innerSet.add("null");
|
|
691
710
|
return innerSet;
|
|
692
711
|
}
|
|
@@ -694,30 +713,31 @@ function walk(schema, depth) {
|
|
|
694
713
|
case "readonly":
|
|
695
714
|
case "catch": {
|
|
696
715
|
const inner = unwrapInner(schema);
|
|
697
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
716
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth, maxDepth);
|
|
698
717
|
}
|
|
699
718
|
case "pipe": {
|
|
700
719
|
const inner = unwrapPipe(schema);
|
|
701
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
720
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth, maxDepth);
|
|
702
721
|
}
|
|
703
722
|
case "lazy": {
|
|
723
|
+
if (lazyDepth >= maxDepth) return new Set(PERMISSIVE);
|
|
704
724
|
const inner = unwrapLazy(schema);
|
|
705
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
725
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth + 1, maxDepth);
|
|
706
726
|
}
|
|
707
727
|
case "union":
|
|
708
728
|
case "discriminated-union": {
|
|
709
729
|
const options = getUnionOptions(schema);
|
|
710
730
|
const out = /* @__PURE__ */ new Set();
|
|
711
731
|
for (const opt of options) {
|
|
712
|
-
for (const k of walk(opt,
|
|
732
|
+
for (const k of walk(opt, lazyDepth, maxDepth)) out.add(k);
|
|
713
733
|
}
|
|
714
734
|
return out.size === 0 ? new Set(PERMISSIVE) : out;
|
|
715
735
|
}
|
|
716
736
|
case "intersection": {
|
|
717
737
|
const left = getIntersectionLeft(schema);
|
|
718
738
|
const right = getIntersectionRight(schema);
|
|
719
|
-
const leftSet = left === void 0 ? new Set(PERMISSIVE) : walk(left,
|
|
720
|
-
const rightSet = right === void 0 ? new Set(PERMISSIVE) : walk(right,
|
|
739
|
+
const leftSet = left === void 0 ? new Set(PERMISSIVE) : walk(left, lazyDepth, maxDepth);
|
|
740
|
+
const rightSet = right === void 0 ? new Set(PERMISSIVE) : walk(right, lazyDepth, maxDepth);
|
|
721
741
|
const out = /* @__PURE__ */ new Set();
|
|
722
742
|
for (const k of leftSet) if (rightSet.has(k)) out.add(k);
|
|
723
743
|
return out;
|
|
@@ -733,6 +753,8 @@ function walk(schema, depth) {
|
|
|
733
753
|
case "promise":
|
|
734
754
|
case "custom":
|
|
735
755
|
case "template-literal":
|
|
756
|
+
case "transform":
|
|
757
|
+
return new Set(PERMISSIVE);
|
|
736
758
|
default:
|
|
737
759
|
return new Set(PERMISSIVE);
|
|
738
760
|
}
|
|
@@ -766,13 +788,13 @@ function slimKindOfRaw(value) {
|
|
|
766
788
|
}
|
|
767
789
|
|
|
768
790
|
const PATH_SEPARATOR$1 = ".";
|
|
769
|
-
function getNestedZodSchemasAtPath(schema, path) {
|
|
770
|
-
if (Array.isArray(path)) return walkSegments(schema, path.map(String));
|
|
791
|
+
function getNestedZodSchemasAtPath(schema, path, maxRecursionDepth) {
|
|
792
|
+
if (Array.isArray(path)) return walkSegments(schema, path.map(String), maxRecursionDepth, 0);
|
|
771
793
|
const pathString = path;
|
|
772
794
|
if (pathString.length === 0) return [schema];
|
|
773
|
-
return walkSegments(schema, pathString.split(PATH_SEPARATOR$1));
|
|
795
|
+
return walkSegments(schema, pathString.split(PATH_SEPARATOR$1), maxRecursionDepth, 0);
|
|
774
796
|
}
|
|
775
|
-
function walkSegments(schema, segments) {
|
|
797
|
+
function walkSegments(schema, segments, maxDepth, lazyDepth) {
|
|
776
798
|
if (segments.length === 0) return [schema];
|
|
777
799
|
const [head, ...rest] = segments;
|
|
778
800
|
if (head === void 0) return [schema];
|
|
@@ -782,23 +804,25 @@ function walkSegments(schema, segments) {
|
|
|
782
804
|
const shape = getObjectShape(schema);
|
|
783
805
|
if (!Object.hasOwn(shape, head)) return [];
|
|
784
806
|
const next = shape[head];
|
|
785
|
-
return next === void 0 ? [] : walkSegments(next, rest);
|
|
807
|
+
return next === void 0 ? [] : walkSegments(next, rest, maxDepth, lazyDepth);
|
|
786
808
|
}
|
|
787
809
|
case "array":
|
|
788
|
-
return walkSegments(getArrayElement(schema), rest);
|
|
810
|
+
return walkSegments(getArrayElement(schema), rest, maxDepth, lazyDepth);
|
|
789
811
|
case "set":
|
|
790
|
-
return walkSegments(getSetValueType(schema), rest);
|
|
812
|
+
return walkSegments(getSetValueType(schema), rest, maxDepth, lazyDepth);
|
|
791
813
|
case "record":
|
|
792
|
-
return walkSegments(getRecordValueType(schema), rest);
|
|
814
|
+
return walkSegments(getRecordValueType(schema), rest, maxDepth, lazyDepth);
|
|
793
815
|
case "tuple": {
|
|
794
816
|
const index = Number(head);
|
|
795
817
|
if (!Number.isInteger(index)) return [];
|
|
796
818
|
const items = getTupleItems(schema);
|
|
797
819
|
const item = items[index];
|
|
798
|
-
return item === void 0 ? [] : walkSegments(item, rest);
|
|
820
|
+
return item === void 0 ? [] : walkSegments(item, rest, maxDepth, lazyDepth);
|
|
799
821
|
}
|
|
800
822
|
case "union":
|
|
801
|
-
return getUnionOptions(schema).flatMap(
|
|
823
|
+
return getUnionOptions(schema).flatMap(
|
|
824
|
+
(opt) => walkSegments(opt, segments, maxDepth, lazyDepth)
|
|
825
|
+
);
|
|
802
826
|
case "discriminated-union": {
|
|
803
827
|
const options = getDiscriminatedOptions(schema);
|
|
804
828
|
const matching = options.filter((opt) => {
|
|
@@ -806,7 +830,7 @@ function walkSegments(schema, segments) {
|
|
|
806
830
|
return Object.hasOwn(shape, head);
|
|
807
831
|
});
|
|
808
832
|
const candidates = matching.length > 0 ? matching : options;
|
|
809
|
-
return candidates.flatMap((opt) => walkSegments(opt, segments));
|
|
833
|
+
return candidates.flatMap((opt) => walkSegments(opt, segments, maxDepth, lazyDepth));
|
|
810
834
|
}
|
|
811
835
|
case "optional":
|
|
812
836
|
case "nullable":
|
|
@@ -814,21 +838,22 @@ function walkSegments(schema, segments) {
|
|
|
814
838
|
case "readonly":
|
|
815
839
|
case "catch": {
|
|
816
840
|
const inner = unwrapInner(schema);
|
|
817
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
841
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth);
|
|
818
842
|
}
|
|
819
843
|
case "pipe": {
|
|
820
844
|
const inner = unwrapPipe(schema);
|
|
821
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
845
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth);
|
|
822
846
|
}
|
|
823
847
|
case "lazy": {
|
|
848
|
+
if (lazyDepth >= maxDepth) return [];
|
|
824
849
|
const inner = unwrapLazy(schema);
|
|
825
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
850
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth + 1);
|
|
826
851
|
}
|
|
827
852
|
case "intersection": {
|
|
828
853
|
const left = getIntersectionLeft(schema);
|
|
829
854
|
const right = getIntersectionRight(schema);
|
|
830
|
-
const leftResults = left === void 0 ? [] : walkSegments(left, segments);
|
|
831
|
-
const rightResults = right === void 0 ? [] : walkSegments(right, segments);
|
|
855
|
+
const leftResults = left === void 0 ? [] : walkSegments(left, segments, maxDepth, lazyDepth);
|
|
856
|
+
const rightResults = right === void 0 ? [] : walkSegments(right, segments, maxDepth, lazyDepth);
|
|
832
857
|
return [...leftResults, ...rightResults];
|
|
833
858
|
}
|
|
834
859
|
// Leaf types — can't descend further.
|
|
@@ -849,6 +874,7 @@ function walkSegments(schema, segments) {
|
|
|
849
874
|
case "promise":
|
|
850
875
|
case "custom":
|
|
851
876
|
case "template-literal":
|
|
877
|
+
case "transform":
|
|
852
878
|
return [];
|
|
853
879
|
default: {
|
|
854
880
|
const _exhaustive = kind;
|
|
@@ -960,6 +986,7 @@ function stripRefinements(schema) {
|
|
|
960
986
|
case "promise":
|
|
961
987
|
case "custom":
|
|
962
988
|
case "template-literal":
|
|
989
|
+
case "transform":
|
|
963
990
|
return schema;
|
|
964
991
|
default: {
|
|
965
992
|
const _exhaustive = kind;
|
|
@@ -1083,6 +1110,7 @@ function stripAsyncChecks(schema) {
|
|
|
1083
1110
|
case "promise":
|
|
1084
1111
|
case "custom":
|
|
1085
1112
|
case "template-literal":
|
|
1113
|
+
case "transform":
|
|
1086
1114
|
return s;
|
|
1087
1115
|
default: {
|
|
1088
1116
|
const _exhaustive = kind;
|
|
@@ -1092,34 +1120,37 @@ function stripAsyncChecks(schema) {
|
|
|
1092
1120
|
}
|
|
1093
1121
|
return recurse(schema);
|
|
1094
1122
|
}
|
|
1095
|
-
function getSlimSchema(schema, stripConfig) {
|
|
1123
|
+
function getSlimSchema(schema, stripConfig, maxRecursionDepth) {
|
|
1124
|
+
return walkSlim(schema, stripConfig, maxRecursionDepth, 0);
|
|
1125
|
+
}
|
|
1126
|
+
function walkSlim(schema, stripConfig, maxDepth, lazyDepth) {
|
|
1096
1127
|
const kind = kindOf(schema);
|
|
1097
1128
|
switch (kind) {
|
|
1098
1129
|
case "optional": {
|
|
1099
1130
|
const inner = unwrapInner(schema) ?? schema;
|
|
1100
|
-
const slimmedInner =
|
|
1131
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1101
1132
|
return stripConfig.stripOptional === true ? slimmedInner : slimmedInner.optional();
|
|
1102
1133
|
}
|
|
1103
1134
|
case "nullable": {
|
|
1104
1135
|
const inner = unwrapInner(schema) ?? schema;
|
|
1105
|
-
const slimmedInner =
|
|
1136
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1106
1137
|
return stripConfig.stripNullable === true ? slimmedInner : slimmedInner.nullable();
|
|
1107
1138
|
}
|
|
1108
1139
|
case "default": {
|
|
1109
1140
|
const inner = unwrapInner(schema) ?? schema;
|
|
1110
|
-
const slimmedInner =
|
|
1141
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1111
1142
|
if (stripConfig.stripDefaultValues === true) return slimmedInner;
|
|
1112
1143
|
const defaultValue = getDefaultValue(schema);
|
|
1113
1144
|
return slimmedInner.default(defaultValue);
|
|
1114
1145
|
}
|
|
1115
1146
|
case "readonly": {
|
|
1116
1147
|
const inner = unwrapInner(schema);
|
|
1117
|
-
return inner === void 0 ? schema :
|
|
1148
|
+
return inner === void 0 ? schema : walkSlim(inner, stripConfig, maxDepth, lazyDepth).readonly();
|
|
1118
1149
|
}
|
|
1119
1150
|
case "pipe": {
|
|
1120
1151
|
if (stripConfig.stripPipe === true) {
|
|
1121
1152
|
const inner = unwrapPipe(schema) ?? schema;
|
|
1122
|
-
return
|
|
1153
|
+
return walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1123
1154
|
}
|
|
1124
1155
|
return schema;
|
|
1125
1156
|
}
|
|
@@ -1127,20 +1158,30 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1127
1158
|
const shape = getObjectShape(schema);
|
|
1128
1159
|
const next = {};
|
|
1129
1160
|
for (const [k, v] of Object.entries(shape)) {
|
|
1130
|
-
next[k] =
|
|
1161
|
+
next[k] = walkSlim(v, stripConfig, maxDepth, lazyDepth);
|
|
1131
1162
|
}
|
|
1132
1163
|
return carryChecks(zod.z.object(next), schema, stripConfig);
|
|
1133
1164
|
}
|
|
1134
1165
|
case "array": {
|
|
1135
1166
|
const element = getArrayElement(schema);
|
|
1136
|
-
return carryChecks(
|
|
1167
|
+
return carryChecks(
|
|
1168
|
+
zod.z.array(walkSlim(element, stripConfig, maxDepth, lazyDepth)),
|
|
1169
|
+
schema,
|
|
1170
|
+
stripConfig
|
|
1171
|
+
);
|
|
1137
1172
|
}
|
|
1138
1173
|
case "set": {
|
|
1139
1174
|
const valueType = getSetValueType(schema);
|
|
1140
|
-
return carryChecks(
|
|
1175
|
+
return carryChecks(
|
|
1176
|
+
zod.z.set(walkSlim(valueType, stripConfig, maxDepth, lazyDepth)),
|
|
1177
|
+
schema,
|
|
1178
|
+
stripConfig
|
|
1179
|
+
);
|
|
1141
1180
|
}
|
|
1142
1181
|
case "tuple": {
|
|
1143
|
-
const items = getTupleItems(schema).map(
|
|
1182
|
+
const items = getTupleItems(schema).map(
|
|
1183
|
+
(it) => walkSlim(it, stripConfig, maxDepth, lazyDepth)
|
|
1184
|
+
);
|
|
1144
1185
|
const rebuilt = zod.z.tuple(
|
|
1145
1186
|
items
|
|
1146
1187
|
);
|
|
@@ -1148,18 +1189,20 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1148
1189
|
}
|
|
1149
1190
|
case "record": {
|
|
1150
1191
|
const keyType = getRecordKeyType(schema);
|
|
1151
|
-
const valueType =
|
|
1192
|
+
const valueType = walkSlim(getRecordValueType(schema), stripConfig, maxDepth, lazyDepth);
|
|
1152
1193
|
const rebuilt = zod.z.record(keyType, valueType);
|
|
1153
1194
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1154
1195
|
}
|
|
1155
1196
|
case "union": {
|
|
1156
|
-
const options = getUnionOptions(schema).map(
|
|
1197
|
+
const options = getUnionOptions(schema).map(
|
|
1198
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1199
|
+
);
|
|
1157
1200
|
const rebuilt = zod.z.union(options);
|
|
1158
1201
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1159
1202
|
}
|
|
1160
1203
|
case "discriminated-union": {
|
|
1161
1204
|
const options = getDiscriminatedOptions(schema).map(
|
|
1162
|
-
(opt) =>
|
|
1205
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1163
1206
|
);
|
|
1164
1207
|
const discriminator = getDiscriminator(schema);
|
|
1165
1208
|
if (discriminator === void 0) return schema;
|
|
@@ -1189,23 +1232,29 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1189
1232
|
case "template-literal":
|
|
1190
1233
|
return schema;
|
|
1191
1234
|
case "lazy": {
|
|
1235
|
+
if (lazyDepth >= maxDepth) return schema;
|
|
1192
1236
|
const inner = unwrapLazy(schema);
|
|
1193
1237
|
if (inner === void 0) return schema;
|
|
1194
|
-
const slimmedInner =
|
|
1238
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth + 1);
|
|
1195
1239
|
return zod.z.lazy(() => slimmedInner);
|
|
1196
1240
|
}
|
|
1197
1241
|
case "intersection": {
|
|
1198
1242
|
const left = getIntersectionLeft(schema);
|
|
1199
1243
|
const right = getIntersectionRight(schema);
|
|
1200
1244
|
if (left === void 0 || right === void 0) return schema;
|
|
1201
|
-
return zod.z.intersection(
|
|
1245
|
+
return zod.z.intersection(
|
|
1246
|
+
walkSlim(left, stripConfig, maxDepth, lazyDepth),
|
|
1247
|
+
walkSlim(right, stripConfig, maxDepth, lazyDepth)
|
|
1248
|
+
);
|
|
1202
1249
|
}
|
|
1203
1250
|
case "catch": {
|
|
1204
1251
|
const inner = unwrapInner(schema);
|
|
1205
1252
|
if (inner === void 0) return schema;
|
|
1206
|
-
const slimmedInner =
|
|
1253
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1207
1254
|
return slimmedInner.catch(getCatchDefault(schema));
|
|
1208
1255
|
}
|
|
1256
|
+
case "transform":
|
|
1257
|
+
return schema;
|
|
1209
1258
|
default: {
|
|
1210
1259
|
const _exhaustive = kind;
|
|
1211
1260
|
throw new Error(`getSlimSchema: unhandled ZodKind '${_exhaustive}'`);
|
|
@@ -1213,23 +1262,23 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1213
1262
|
}
|
|
1214
1263
|
}
|
|
1215
1264
|
|
|
1216
|
-
function deriveDefault(schema, useDefault) {
|
|
1217
|
-
return defaultForKind(kindOf(schema), schema, useDefault);
|
|
1265
|
+
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
1266
|
+
return defaultForKind(kindOf(schema), schema, useDefault, maxRecursionDepth, 0);
|
|
1218
1267
|
}
|
|
1219
|
-
function defaultForKind(kind, schema, useDefault) {
|
|
1268
|
+
function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
1220
1269
|
switch (kind) {
|
|
1221
1270
|
case "object": {
|
|
1222
1271
|
const shape = getObjectShape(schema);
|
|
1223
1272
|
const out = {};
|
|
1224
1273
|
for (const [key, subSchema] of Object.entries(shape)) {
|
|
1225
|
-
out[key] =
|
|
1274
|
+
out[key] = defaultForKind(kindOf(subSchema), subSchema, useDefault, maxDepth, lazyDepth);
|
|
1226
1275
|
}
|
|
1227
1276
|
return out;
|
|
1228
1277
|
}
|
|
1229
1278
|
case "default": {
|
|
1230
1279
|
if (useDefault) return getDefaultValue(schema);
|
|
1231
1280
|
const inner = unwrapInner(schema);
|
|
1232
|
-
return inner === void 0 ? void 0 :
|
|
1281
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1233
1282
|
}
|
|
1234
1283
|
case "optional":
|
|
1235
1284
|
return void 0;
|
|
@@ -1237,11 +1286,11 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1237
1286
|
return null;
|
|
1238
1287
|
case "readonly": {
|
|
1239
1288
|
const inner = unwrapInner(schema);
|
|
1240
|
-
return inner === void 0 ? void 0 :
|
|
1289
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1241
1290
|
}
|
|
1242
1291
|
case "pipe": {
|
|
1243
1292
|
const inner = unwrapPipe(schema);
|
|
1244
|
-
return inner === void 0 ? void 0 :
|
|
1293
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1245
1294
|
}
|
|
1246
1295
|
case "array":
|
|
1247
1296
|
return [];
|
|
@@ -1251,16 +1300,18 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1251
1300
|
return {};
|
|
1252
1301
|
case "tuple": {
|
|
1253
1302
|
const items = getTupleItems(schema);
|
|
1254
|
-
return items.map(
|
|
1303
|
+
return items.map(
|
|
1304
|
+
(item) => defaultForKind(kindOf(item), item, useDefault, maxDepth, lazyDepth)
|
|
1305
|
+
);
|
|
1255
1306
|
}
|
|
1256
1307
|
case "union": {
|
|
1257
1308
|
const options = getUnionOptions(schema);
|
|
1258
1309
|
const first = options[0];
|
|
1259
|
-
return first === void 0 ? void 0 :
|
|
1310
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1260
1311
|
}
|
|
1261
1312
|
case "discriminated-union": {
|
|
1262
1313
|
const first = getDiscriminatedUnionFirstOption(schema);
|
|
1263
|
-
return first === void 0 ? void 0 :
|
|
1314
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1264
1315
|
}
|
|
1265
1316
|
case "string":
|
|
1266
1317
|
return "";
|
|
@@ -1287,20 +1338,21 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1287
1338
|
case "nan":
|
|
1288
1339
|
return NaN;
|
|
1289
1340
|
case "lazy": {
|
|
1341
|
+
if (lazyDepth >= maxDepth) return void 0;
|
|
1290
1342
|
const inner = unwrapLazy(schema);
|
|
1291
|
-
return inner === void 0 ? void 0 :
|
|
1343
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth + 1);
|
|
1292
1344
|
}
|
|
1293
1345
|
case "intersection": {
|
|
1294
1346
|
const left = getIntersectionLeft(schema);
|
|
1295
1347
|
const right = getIntersectionRight(schema);
|
|
1296
|
-
const l = left === void 0 ? void 0 :
|
|
1297
|
-
const r = right === void 0 ? void 0 :
|
|
1348
|
+
const l = left === void 0 ? void 0 : defaultForKind(kindOf(left), left, useDefault, maxDepth, lazyDepth);
|
|
1349
|
+
const r = right === void 0 ? void 0 : defaultForKind(kindOf(right), right, useDefault, maxDepth, lazyDepth);
|
|
1298
1350
|
return mergeDeep(l, r);
|
|
1299
1351
|
}
|
|
1300
1352
|
case "catch": {
|
|
1301
1353
|
if (useDefault) return getCatchDefault(schema);
|
|
1302
1354
|
const inner = unwrapInner(schema);
|
|
1303
|
-
return inner === void 0 ? void 0 :
|
|
1355
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1304
1356
|
}
|
|
1305
1357
|
case "any":
|
|
1306
1358
|
case "unknown":
|
|
@@ -1309,6 +1361,7 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1309
1361
|
case "promise":
|
|
1310
1362
|
case "custom":
|
|
1311
1363
|
case "template-literal":
|
|
1364
|
+
case "transform":
|
|
1312
1365
|
return void 0;
|
|
1313
1366
|
default: {
|
|
1314
1367
|
const _exhaustive = kind;
|
|
@@ -1333,14 +1386,18 @@ function mergeDeep(base, override) {
|
|
|
1333
1386
|
return result;
|
|
1334
1387
|
}
|
|
1335
1388
|
function getDefaultValuesFromZodSchema(opts) {
|
|
1336
|
-
const { schema, useDefaultSchemaValues, constraints } = opts;
|
|
1337
|
-
const initial = deriveDefault(schema, useDefaultSchemaValues);
|
|
1389
|
+
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
1390
|
+
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
1338
1391
|
const merged = mergeDeep(initial, constraints);
|
|
1339
|
-
const slimSchema = getSlimSchema(
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1392
|
+
const slimSchema = getSlimSchema(
|
|
1393
|
+
schema,
|
|
1394
|
+
{
|
|
1395
|
+
stripDefaultValues: true,
|
|
1396
|
+
stripPipe: true,
|
|
1397
|
+
stripRefinements: true
|
|
1398
|
+
},
|
|
1399
|
+
maxRecursionDepth
|
|
1400
|
+
);
|
|
1344
1401
|
const firstParse = slimSchema.safeParse(merged);
|
|
1345
1402
|
if (firstParse.success) {
|
|
1346
1403
|
return { data: firstParse.data, success: true, slimSchema };
|
|
@@ -1348,16 +1405,16 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1348
1405
|
let fixedData = merged;
|
|
1349
1406
|
for (const issue of firstParse.error.issues) {
|
|
1350
1407
|
const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
|
|
1351
|
-
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments);
|
|
1408
|
+
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments, maxRecursionDepth);
|
|
1352
1409
|
if (candidates.length === 0) continue;
|
|
1353
1410
|
const candidate = candidates[0];
|
|
1354
1411
|
if (candidate === void 0) continue;
|
|
1355
1412
|
const valueAtPath = useFormContext.getAtPath(merged, pathSegments);
|
|
1356
|
-
const slimKinds = slimPrimitivesOf(candidate);
|
|
1413
|
+
const slimKinds = slimPrimitivesOf(candidate, maxRecursionDepth);
|
|
1357
1414
|
if (slimKinds.size > 0 && slimKinds.has(useFormContext.slimKindOf(valueAtPath))) {
|
|
1358
1415
|
continue;
|
|
1359
1416
|
}
|
|
1360
|
-
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues);
|
|
1417
|
+
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1361
1418
|
if (fixValue === SKIP) continue;
|
|
1362
1419
|
fixedData = pathSegments.length === 0 ? fixValue : useFormContext.setAtPath(fixedData, pathSegments, fixValue);
|
|
1363
1420
|
}
|
|
@@ -1368,21 +1425,22 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1368
1425
|
return { data: fixedData, success: false, slimSchema };
|
|
1369
1426
|
}
|
|
1370
1427
|
const SKIP = Symbol("atta:skip-fix");
|
|
1371
|
-
function defaultFromIssue(issue, candidate, useDefaultSchemaValues) {
|
|
1428
|
+
function defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth) {
|
|
1372
1429
|
if (issue.code === "invalid_type") {
|
|
1373
1430
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
1374
1431
|
if (du !== void 0) {
|
|
1375
1432
|
const first = getDiscriminatedUnionFirstOption(du);
|
|
1376
|
-
if (first !== void 0)
|
|
1433
|
+
if (first !== void 0)
|
|
1434
|
+
return deriveDefault(first, useDefaultSchemaValues, maxRecursionDepth);
|
|
1377
1435
|
}
|
|
1378
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1436
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1379
1437
|
}
|
|
1380
1438
|
if (issue.code === "invalid_value") {
|
|
1381
1439
|
const values = issue.values;
|
|
1382
1440
|
if (values !== void 0 && values.length > 0) return values[0];
|
|
1383
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1441
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1384
1442
|
}
|
|
1385
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1443
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1386
1444
|
}
|
|
1387
1445
|
|
|
1388
1446
|
const PATH_SEPARATOR = ".";
|
|
@@ -1472,7 +1530,8 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
1472
1530
|
function zodV4Adapter(rootSchema) {
|
|
1473
1531
|
assertZodVersion(rootSchema);
|
|
1474
1532
|
assertSupportedKinds(rootSchema);
|
|
1475
|
-
return (formKey) => {
|
|
1533
|
+
return (formKey, options) => {
|
|
1534
|
+
const maxRecursionDepth = options.maxRecursionDepth;
|
|
1476
1535
|
const leafCache = /* @__PURE__ */ new Map();
|
|
1477
1536
|
let asyncValidationFlag = null;
|
|
1478
1537
|
return {
|
|
@@ -1485,13 +1544,16 @@ function zodV4Adapter(rootSchema) {
|
|
|
1485
1544
|
const { data } = getDefaultValuesFromZodSchema({
|
|
1486
1545
|
schema: rootSchema,
|
|
1487
1546
|
useDefaultSchemaValues: config.useDefaultSchemaValues,
|
|
1488
|
-
constraints: config.constraints
|
|
1547
|
+
constraints: config.constraints,
|
|
1548
|
+
maxRecursionDepth
|
|
1489
1549
|
});
|
|
1490
1550
|
if (config.strict !== false) {
|
|
1491
1551
|
try {
|
|
1492
|
-
const strictResult = rootSchema.safeParse(
|
|
1552
|
+
const strictResult = rootSchema.safeParse(
|
|
1553
|
+
data
|
|
1554
|
+
);
|
|
1493
1555
|
if (strictResult.success) {
|
|
1494
|
-
return { data
|
|
1556
|
+
return { data, errors: void 0, success: true, formKey };
|
|
1495
1557
|
}
|
|
1496
1558
|
return {
|
|
1497
1559
|
data,
|
|
@@ -1519,15 +1581,46 @@ function zodV4Adapter(rootSchema) {
|
|
|
1519
1581
|
}
|
|
1520
1582
|
return { data, errors: void 0, success: true, formKey };
|
|
1521
1583
|
},
|
|
1584
|
+
normalizeWriteValueAtPath(value, path) {
|
|
1585
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1586
|
+
const [first] = candidates;
|
|
1587
|
+
if (first === void 0) return value;
|
|
1588
|
+
let current = first;
|
|
1589
|
+
let result = value;
|
|
1590
|
+
for (let i = 0; i < 64; i++) {
|
|
1591
|
+
if (kindOf(current) !== "pipe") break;
|
|
1592
|
+
const pipeIn = unwrapPipeIn(current);
|
|
1593
|
+
if (pipeIn === void 0 || kindOf(pipeIn) !== "transform") break;
|
|
1594
|
+
const fn = readTransformFn(pipeIn);
|
|
1595
|
+
if (typeof fn !== "function") break;
|
|
1596
|
+
let next;
|
|
1597
|
+
try {
|
|
1598
|
+
next = fn(result);
|
|
1599
|
+
} catch (cause) {
|
|
1600
|
+
throw new Error(
|
|
1601
|
+
`[attaform] input normalization at path "${path.join(".")}" threw \u2014 write rejected.`,
|
|
1602
|
+
{ cause }
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
if (next instanceof Promise) {
|
|
1606
|
+
return value;
|
|
1607
|
+
}
|
|
1608
|
+
result = next;
|
|
1609
|
+
const out = unwrapPipeOut(current);
|
|
1610
|
+
if (out === void 0) break;
|
|
1611
|
+
current = out;
|
|
1612
|
+
}
|
|
1613
|
+
return result;
|
|
1614
|
+
},
|
|
1522
1615
|
getDefaultAtPath(path) {
|
|
1523
|
-
if (path.length === 0) return deriveDefault(rootSchema, true);
|
|
1524
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1616
|
+
if (path.length === 0) return deriveDefault(rootSchema, true, maxRecursionDepth);
|
|
1617
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1525
1618
|
if (first === void 0) return void 0;
|
|
1526
|
-
return deriveDefault(unwrapStructuralWrappers(first), true);
|
|
1619
|
+
return deriveDefault(unwrapStructuralWrappers(first), true, maxRecursionDepth);
|
|
1527
1620
|
},
|
|
1528
1621
|
arrayShapeAtPath(path) {
|
|
1529
1622
|
if (path.length === 0) return void 0;
|
|
1530
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1623
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1531
1624
|
if (first === void 0) return void 0;
|
|
1532
1625
|
const peeled = peelAllWrappers(first);
|
|
1533
1626
|
const kind = kindOf(peeled);
|
|
@@ -1536,13 +1629,13 @@ function zodV4Adapter(rootSchema) {
|
|
|
1536
1629
|
return void 0;
|
|
1537
1630
|
},
|
|
1538
1631
|
getSchemasAtPath(path) {
|
|
1539
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1632
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1540
1633
|
return resolved.map(
|
|
1541
1634
|
(schema) => ({
|
|
1542
1635
|
fingerprint: () => fingerprintZodSchema(schema),
|
|
1543
1636
|
needsAsyncValidation: () => containsAsyncRefine(schema),
|
|
1544
1637
|
getDefaultValues: () => ({
|
|
1545
|
-
data: deriveDefault(schema, true),
|
|
1638
|
+
data: deriveDefault(schema, true, maxRecursionDepth),
|
|
1546
1639
|
errors: void 0,
|
|
1547
1640
|
success: true,
|
|
1548
1641
|
formKey
|
|
@@ -1565,11 +1658,11 @@ function zodV4Adapter(rootSchema) {
|
|
|
1565
1658
|
},
|
|
1566
1659
|
getSlimPrimitiveTypesAtPath(path) {
|
|
1567
1660
|
if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
|
|
1568
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1661
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1569
1662
|
if (resolved.length === 0) return /* @__PURE__ */ new Set();
|
|
1570
1663
|
const out = /* @__PURE__ */ new Set();
|
|
1571
1664
|
for (const candidate of resolved) {
|
|
1572
|
-
for (const k of slimPrimitivesOf(candidate)) out.add(k);
|
|
1665
|
+
for (const k of slimPrimitivesOf(candidate, maxRecursionDepth)) out.add(k);
|
|
1573
1666
|
}
|
|
1574
1667
|
return out;
|
|
1575
1668
|
},
|
|
@@ -1584,15 +1677,15 @@ function zodV4Adapter(rootSchema) {
|
|
|
1584
1677
|
},
|
|
1585
1678
|
isRequiredAtPath(path) {
|
|
1586
1679
|
if (path.length === 0) return true;
|
|
1587
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1680
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1588
1681
|
if (resolved.length === 0) return false;
|
|
1589
1682
|
return resolved.every((candidate) => isLeafRequired(candidate));
|
|
1590
1683
|
},
|
|
1591
1684
|
getFieldMetaAtPath(path) {
|
|
1592
|
-
return resolveFieldMetaAtPath(rootSchema, path);
|
|
1685
|
+
return resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth);
|
|
1593
1686
|
},
|
|
1594
1687
|
getUnionDiscriminatorAtPath(path) {
|
|
1595
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1688
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1596
1689
|
let matchedUnion;
|
|
1597
1690
|
for (const candidate of candidates) {
|
|
1598
1691
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
@@ -1603,24 +1696,35 @@ function zodV4Adapter(rootSchema) {
|
|
|
1603
1696
|
if (matchedUnion === void 0) return void 0;
|
|
1604
1697
|
const discKey = getDiscriminator(matchedUnion);
|
|
1605
1698
|
if (discKey === void 0) return void 0;
|
|
1606
|
-
const
|
|
1699
|
+
const options2 = getDiscriminatedOptions(matchedUnion);
|
|
1700
|
+
const literalSet = /* @__PURE__ */ new Set();
|
|
1701
|
+
for (const opt of options2) {
|
|
1702
|
+
const shape = getObjectShape(opt);
|
|
1703
|
+
const litSchema = shape[discKey];
|
|
1704
|
+
if (litSchema === void 0) continue;
|
|
1705
|
+
if (kindOf(litSchema) !== "literal") continue;
|
|
1706
|
+
for (const v of getLiteralValues(litSchema)) literalSet.add(v);
|
|
1707
|
+
}
|
|
1607
1708
|
return {
|
|
1608
1709
|
discriminatorKey: discKey,
|
|
1609
1710
|
getVariantDefault(value) {
|
|
1610
|
-
for (const opt of
|
|
1711
|
+
for (const opt of options2) {
|
|
1611
1712
|
const shape = getObjectShape(opt);
|
|
1612
1713
|
const litSchema = shape[discKey];
|
|
1613
1714
|
if (litSchema === void 0) continue;
|
|
1614
1715
|
if (kindOf(litSchema) !== "literal") continue;
|
|
1615
1716
|
const literalValues = getLiteralValues(litSchema);
|
|
1616
|
-
if (literalValues.includes(value)) return deriveDefault(opt, true);
|
|
1717
|
+
if (literalValues.includes(value)) return deriveDefault(opt, true, maxRecursionDepth);
|
|
1617
1718
|
}
|
|
1618
1719
|
return void 0;
|
|
1720
|
+
},
|
|
1721
|
+
isVariantSelected(value) {
|
|
1722
|
+
return literalSet.has(value);
|
|
1619
1723
|
}
|
|
1620
1724
|
};
|
|
1621
1725
|
},
|
|
1622
|
-
validateAtPath(data, path,
|
|
1623
|
-
const trySync =
|
|
1726
|
+
validateAtPath(data, path, options2) {
|
|
1727
|
+
const trySync = options2?.sync === true;
|
|
1624
1728
|
if (trySync) {
|
|
1625
1729
|
try {
|
|
1626
1730
|
return runSync();
|
|
@@ -1638,13 +1742,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1638
1742
|
formKey
|
|
1639
1743
|
};
|
|
1640
1744
|
}
|
|
1641
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1745
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1642
1746
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1643
1747
|
const aggregated = [];
|
|
1644
1748
|
for (const candidate of resolved) {
|
|
1645
1749
|
const result = candidate.safeParse(data);
|
|
1646
1750
|
if (result.success) {
|
|
1647
|
-
return {
|
|
1751
|
+
return {
|
|
1752
|
+
data: result.data,
|
|
1753
|
+
errors: void 0,
|
|
1754
|
+
success: true,
|
|
1755
|
+
formKey
|
|
1756
|
+
};
|
|
1648
1757
|
}
|
|
1649
1758
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1650
1759
|
}
|
|
@@ -1652,7 +1761,9 @@ function zodV4Adapter(rootSchema) {
|
|
|
1652
1761
|
}
|
|
1653
1762
|
async function runAsync() {
|
|
1654
1763
|
if (path === void 0) {
|
|
1655
|
-
const result = await rootSchema.safeParseAsync(
|
|
1764
|
+
const result = await rootSchema.safeParseAsync(
|
|
1765
|
+
data
|
|
1766
|
+
);
|
|
1656
1767
|
return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
|
|
1657
1768
|
data: void 0,
|
|
1658
1769
|
errors: zodIssuesToValidationErrors(result.error.issues, formKey),
|
|
@@ -1660,13 +1771,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1660
1771
|
formKey
|
|
1661
1772
|
};
|
|
1662
1773
|
}
|
|
1663
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1774
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1664
1775
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1665
1776
|
const aggregated = [];
|
|
1666
1777
|
for (const candidate of resolved) {
|
|
1667
1778
|
const result = await candidate.safeParseAsync(data);
|
|
1668
1779
|
if (result.success) {
|
|
1669
|
-
return {
|
|
1780
|
+
return {
|
|
1781
|
+
data: result.data,
|
|
1782
|
+
errors: void 0,
|
|
1783
|
+
success: true,
|
|
1784
|
+
formKey
|
|
1785
|
+
};
|
|
1670
1786
|
}
|
|
1671
1787
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1672
1788
|
}
|
|
@@ -1844,6 +1960,7 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress)
|
|
|
1844
1960
|
case "promise":
|
|
1845
1961
|
case "custom":
|
|
1846
1962
|
case "template-literal":
|
|
1963
|
+
case "transform":
|
|
1847
1964
|
return;
|
|
1848
1965
|
}
|
|
1849
1966
|
} finally {
|
|
@@ -1858,9 +1975,9 @@ function consumePayload(schema, counters) {
|
|
|
1858
1975
|
counters.set(schema, idx + 1);
|
|
1859
1976
|
return payload;
|
|
1860
1977
|
}
|
|
1861
|
-
function resolveFieldMetaAtPath(rootSchema, path) {
|
|
1978
|
+
function resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth) {
|
|
1862
1979
|
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1863
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1980
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1864
1981
|
const target = candidates[0];
|
|
1865
1982
|
if (target === void 0) {
|
|
1866
1983
|
return {
|
|
@@ -1894,9 +2011,7 @@ function useForm(configuration) {
|
|
|
1894
2011
|
if (candidate === void 0 || candidate === null || candidate.schema === void 0) {
|
|
1895
2012
|
throw new plugin.InvalidUseFormConfigError();
|
|
1896
2013
|
}
|
|
1897
|
-
const adapter = zodV4Adapter(
|
|
1898
|
-
configuration.schema
|
|
1899
|
-
);
|
|
2014
|
+
const adapter = zodV4Adapter(configuration.schema);
|
|
1900
2015
|
return useFormContext.useAbstractForm({
|
|
1901
2016
|
...configuration,
|
|
1902
2017
|
schema: adapter
|
|
@@ -1910,4 +2025,4 @@ exports.kindOf = kindOf;
|
|
|
1910
2025
|
exports.useForm = useForm;
|
|
1911
2026
|
exports.withMeta = withMeta;
|
|
1912
2027
|
exports.zodV4Adapter = zodV4Adapter;
|
|
1913
|
-
//# sourceMappingURL=attaform.
|
|
2028
|
+
//# sourceMappingURL=attaform.C6_zOf8x.cjs.map
|