attaform 0.16.3 → 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 +27 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -8
- package/dist/index.d.mts +80 -8
- package/dist/index.d.ts +80 -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.KrNw10aW.cjs → attaform.0Wg7UEeX.cjs} +60 -20
- package/dist/shared/attaform.0Wg7UEeX.cjs.map +1 -0
- package/dist/shared/attaform.AOgGyRoI.d.cts +65 -0
- package/dist/shared/{attaform.lFNwBcA3.d.ts → attaform.B0zue7zt.d.ts} +1 -1
- package/dist/shared/{attaform.c_NzdRyc.cjs → attaform.BBM2muQ9.cjs} +7 -3
- package/dist/shared/attaform.BBM2muQ9.cjs.map +1 -0
- package/dist/shared/{attaform.C9Ph2SMx.cjs → attaform.BFumZXY2.cjs} +1514 -391
- package/dist/shared/attaform.BFumZXY2.cjs.map +1 -0
- package/dist/shared/attaform.BQ-iGGWd.d.mts +65 -0
- package/dist/shared/{attaform.DILbdvfo.mjs → attaform.BT55rDNN.mjs} +1514 -393
- package/dist/shared/attaform.BT55rDNN.mjs.map +1 -0
- package/dist/shared/{attaform._EqYNPYF.d.mts → attaform.BYbsV2Wv.d.cts} +738 -138
- package/dist/shared/{attaform._EqYNPYF.d.ts → attaform.BYbsV2Wv.d.mts} +738 -138
- package/dist/shared/{attaform._EqYNPYF.d.cts → attaform.BYbsV2Wv.d.ts} +738 -138
- package/dist/shared/{attaform.DGuGGNg9.cjs → attaform.C6_zOf8x.cjs} +232 -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.XYOMTvuO.mjs → attaform.Cj0pCNVn.mjs} +232 -113
- package/dist/shared/attaform.Cj0pCNVn.mjs.map +1 -0
- package/dist/shared/{attaform.DLnKT7wk.d.cts → attaform.ClfCi1i2.d.mts} +1 -1
- package/dist/shared/{attaform.CFA6y0KF.mjs → attaform.D6Q5ZP8L.mjs} +60 -20
- package/dist/shared/attaform.D6Q5ZP8L.mjs.map +1 -0
- package/dist/shared/{attaform.Bls_kFR6.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.jrxE_xZw.mjs → attaform.h1sq3BFu.mjs} +6 -4
- package/dist/shared/attaform.h1sq3BFu.mjs.map +1 -0
- 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.C9Ph2SMx.cjs.map +0 -1
- package/dist/shared/attaform.CFA6y0KF.mjs.map +0 -1
- package/dist/shared/attaform.DGuGGNg9.cjs.map +0 -1
- package/dist/shared/attaform.DILbdvfo.mjs.map +0 -1
- package/dist/shared/attaform.KrNw10aW.cjs.map +0 -1
- package/dist/shared/attaform.XYOMTvuO.mjs.map +0 -1
- package/dist/shared/attaform.c_NzdRyc.cjs.map +0 -1
- package/dist/shared/attaform.jrxE_xZw.mjs.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;
|
|
@@ -37,6 +37,10 @@ function zodIssuesToValidationErrors(issues, formKey) {
|
|
|
37
37
|
}
|
|
38
38
|
return {
|
|
39
39
|
message: issue.message,
|
|
40
|
+
// Adapter-side paths stay schema-relative — the validation
|
|
41
|
+
// pipeline in `create-form-store.ts` prepends the parent path
|
|
42
|
+
// to absolutise, then routes form-level (absolute path length 0)
|
|
43
|
+
// entries to the empty-string bucket at storage time.
|
|
40
44
|
path: issue.path.map((seg) => typeof seg === "number" ? seg : String(seg)),
|
|
41
45
|
formKey,
|
|
42
46
|
code
|
|
@@ -113,6 +117,8 @@ function kindOf(schema) {
|
|
|
113
117
|
return "intersection";
|
|
114
118
|
case "catch":
|
|
115
119
|
return "catch";
|
|
120
|
+
case "transform":
|
|
121
|
+
return "transform";
|
|
116
122
|
case "promise":
|
|
117
123
|
return "promise";
|
|
118
124
|
case "custom":
|
|
@@ -170,6 +176,18 @@ function unwrapPipe(schema) {
|
|
|
170
176
|
const def = readDef(schema);
|
|
171
177
|
return def?.in ?? def?.out;
|
|
172
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
|
+
}
|
|
173
191
|
function unwrapLazy(schema) {
|
|
174
192
|
const def = readDef(schema);
|
|
175
193
|
const getter = def?.getter;
|
|
@@ -361,11 +379,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
361
379
|
}
|
|
362
380
|
case "lazy": {
|
|
363
381
|
const getter = getLazyGetter(schema);
|
|
364
|
-
if (getter !== void 0 && lazyGetters.includes(getter))
|
|
365
|
-
throw new UnsupportedSchemaError(
|
|
366
|
-
`[attaform/zod] Recursive z.lazy() at '${labelPath(path)}'`
|
|
367
|
-
);
|
|
368
|
-
}
|
|
382
|
+
if (getter !== void 0 && lazyGetters.includes(getter)) return;
|
|
369
383
|
const inner = unwrapLazy(schema);
|
|
370
384
|
if (inner !== void 0) {
|
|
371
385
|
assertSupportedKinds(
|
|
@@ -401,6 +415,7 @@ function assertSupportedKinds(schema, path = [], lazyGetters = []) {
|
|
|
401
415
|
case "promise":
|
|
402
416
|
case "custom":
|
|
403
417
|
case "template-literal":
|
|
418
|
+
case "transform":
|
|
404
419
|
return;
|
|
405
420
|
default: {
|
|
406
421
|
const _exhaustive = kind;
|
|
@@ -419,6 +434,15 @@ function unwrapToDiscriminatedUnion(schema) {
|
|
|
419
434
|
next = unwrapInner(current);
|
|
420
435
|
} else if (kind === "pipe") {
|
|
421
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;
|
|
422
446
|
}
|
|
423
447
|
if (next === void 0) return void 0;
|
|
424
448
|
current = next;
|
|
@@ -546,6 +570,7 @@ function computeFingerprint(schema, cache, inProgress) {
|
|
|
546
570
|
case "promise":
|
|
547
571
|
case "custom":
|
|
548
572
|
case "template-literal":
|
|
573
|
+
case "transform":
|
|
549
574
|
return `${kind}:*`;
|
|
550
575
|
default: {
|
|
551
576
|
const _ = kind;
|
|
@@ -627,12 +652,10 @@ const PERMISSIVE = /* @__PURE__ */ new Set([
|
|
|
627
652
|
"map",
|
|
628
653
|
"set"
|
|
629
654
|
]);
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
return walk(schema, 0);
|
|
655
|
+
function slimPrimitivesOf(schema, maxRecursionDepth) {
|
|
656
|
+
return walk(schema, 0, maxRecursionDepth);
|
|
633
657
|
}
|
|
634
|
-
function walk(schema,
|
|
635
|
-
if (depth > MAX_LAZY_DEPTH) return new Set(PERMISSIVE);
|
|
658
|
+
function walk(schema, lazyDepth, maxDepth) {
|
|
636
659
|
const kind = kindOf(schema);
|
|
637
660
|
switch (kind) {
|
|
638
661
|
case "string":
|
|
@@ -676,13 +699,13 @@ function walk(schema, depth) {
|
|
|
676
699
|
return /* @__PURE__ */ new Set(["set"]);
|
|
677
700
|
case "optional": {
|
|
678
701
|
const inner = unwrapInner(schema);
|
|
679
|
-
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner,
|
|
702
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, lazyDepth, maxDepth);
|
|
680
703
|
innerSet.add("undefined");
|
|
681
704
|
return innerSet;
|
|
682
705
|
}
|
|
683
706
|
case "nullable": {
|
|
684
707
|
const inner = unwrapInner(schema);
|
|
685
|
-
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner,
|
|
708
|
+
const innerSet = inner === void 0 ? /* @__PURE__ */ new Set() : walk(inner, lazyDepth, maxDepth);
|
|
686
709
|
innerSet.add("null");
|
|
687
710
|
return innerSet;
|
|
688
711
|
}
|
|
@@ -690,30 +713,31 @@ function walk(schema, depth) {
|
|
|
690
713
|
case "readonly":
|
|
691
714
|
case "catch": {
|
|
692
715
|
const inner = unwrapInner(schema);
|
|
693
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
716
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth, maxDepth);
|
|
694
717
|
}
|
|
695
718
|
case "pipe": {
|
|
696
719
|
const inner = unwrapPipe(schema);
|
|
697
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
720
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth, maxDepth);
|
|
698
721
|
}
|
|
699
722
|
case "lazy": {
|
|
723
|
+
if (lazyDepth >= maxDepth) return new Set(PERMISSIVE);
|
|
700
724
|
const inner = unwrapLazy(schema);
|
|
701
|
-
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner,
|
|
725
|
+
return inner === void 0 ? new Set(PERMISSIVE) : walk(inner, lazyDepth + 1, maxDepth);
|
|
702
726
|
}
|
|
703
727
|
case "union":
|
|
704
728
|
case "discriminated-union": {
|
|
705
729
|
const options = getUnionOptions(schema);
|
|
706
730
|
const out = /* @__PURE__ */ new Set();
|
|
707
731
|
for (const opt of options) {
|
|
708
|
-
for (const k of walk(opt,
|
|
732
|
+
for (const k of walk(opt, lazyDepth, maxDepth)) out.add(k);
|
|
709
733
|
}
|
|
710
734
|
return out.size === 0 ? new Set(PERMISSIVE) : out;
|
|
711
735
|
}
|
|
712
736
|
case "intersection": {
|
|
713
737
|
const left = getIntersectionLeft(schema);
|
|
714
738
|
const right = getIntersectionRight(schema);
|
|
715
|
-
const leftSet = left === void 0 ? new Set(PERMISSIVE) : walk(left,
|
|
716
|
-
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);
|
|
717
741
|
const out = /* @__PURE__ */ new Set();
|
|
718
742
|
for (const k of leftSet) if (rightSet.has(k)) out.add(k);
|
|
719
743
|
return out;
|
|
@@ -729,6 +753,8 @@ function walk(schema, depth) {
|
|
|
729
753
|
case "promise":
|
|
730
754
|
case "custom":
|
|
731
755
|
case "template-literal":
|
|
756
|
+
case "transform":
|
|
757
|
+
return new Set(PERMISSIVE);
|
|
732
758
|
default:
|
|
733
759
|
return new Set(PERMISSIVE);
|
|
734
760
|
}
|
|
@@ -762,13 +788,13 @@ function slimKindOfRaw(value) {
|
|
|
762
788
|
}
|
|
763
789
|
|
|
764
790
|
const PATH_SEPARATOR$1 = ".";
|
|
765
|
-
function getNestedZodSchemasAtPath(schema, path) {
|
|
766
|
-
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);
|
|
767
793
|
const pathString = path;
|
|
768
794
|
if (pathString.length === 0) return [schema];
|
|
769
|
-
return walkSegments(schema, pathString.split(PATH_SEPARATOR$1));
|
|
795
|
+
return walkSegments(schema, pathString.split(PATH_SEPARATOR$1), maxRecursionDepth, 0);
|
|
770
796
|
}
|
|
771
|
-
function walkSegments(schema, segments) {
|
|
797
|
+
function walkSegments(schema, segments, maxDepth, lazyDepth) {
|
|
772
798
|
if (segments.length === 0) return [schema];
|
|
773
799
|
const [head, ...rest] = segments;
|
|
774
800
|
if (head === void 0) return [schema];
|
|
@@ -778,23 +804,25 @@ function walkSegments(schema, segments) {
|
|
|
778
804
|
const shape = getObjectShape(schema);
|
|
779
805
|
if (!Object.hasOwn(shape, head)) return [];
|
|
780
806
|
const next = shape[head];
|
|
781
|
-
return next === void 0 ? [] : walkSegments(next, rest);
|
|
807
|
+
return next === void 0 ? [] : walkSegments(next, rest, maxDepth, lazyDepth);
|
|
782
808
|
}
|
|
783
809
|
case "array":
|
|
784
|
-
return walkSegments(getArrayElement(schema), rest);
|
|
810
|
+
return walkSegments(getArrayElement(schema), rest, maxDepth, lazyDepth);
|
|
785
811
|
case "set":
|
|
786
|
-
return walkSegments(getSetValueType(schema), rest);
|
|
812
|
+
return walkSegments(getSetValueType(schema), rest, maxDepth, lazyDepth);
|
|
787
813
|
case "record":
|
|
788
|
-
return walkSegments(getRecordValueType(schema), rest);
|
|
814
|
+
return walkSegments(getRecordValueType(schema), rest, maxDepth, lazyDepth);
|
|
789
815
|
case "tuple": {
|
|
790
816
|
const index = Number(head);
|
|
791
817
|
if (!Number.isInteger(index)) return [];
|
|
792
818
|
const items = getTupleItems(schema);
|
|
793
819
|
const item = items[index];
|
|
794
|
-
return item === void 0 ? [] : walkSegments(item, rest);
|
|
820
|
+
return item === void 0 ? [] : walkSegments(item, rest, maxDepth, lazyDepth);
|
|
795
821
|
}
|
|
796
822
|
case "union":
|
|
797
|
-
return getUnionOptions(schema).flatMap(
|
|
823
|
+
return getUnionOptions(schema).flatMap(
|
|
824
|
+
(opt) => walkSegments(opt, segments, maxDepth, lazyDepth)
|
|
825
|
+
);
|
|
798
826
|
case "discriminated-union": {
|
|
799
827
|
const options = getDiscriminatedOptions(schema);
|
|
800
828
|
const matching = options.filter((opt) => {
|
|
@@ -802,7 +830,7 @@ function walkSegments(schema, segments) {
|
|
|
802
830
|
return Object.hasOwn(shape, head);
|
|
803
831
|
});
|
|
804
832
|
const candidates = matching.length > 0 ? matching : options;
|
|
805
|
-
return candidates.flatMap((opt) => walkSegments(opt, segments));
|
|
833
|
+
return candidates.flatMap((opt) => walkSegments(opt, segments, maxDepth, lazyDepth));
|
|
806
834
|
}
|
|
807
835
|
case "optional":
|
|
808
836
|
case "nullable":
|
|
@@ -810,21 +838,22 @@ function walkSegments(schema, segments) {
|
|
|
810
838
|
case "readonly":
|
|
811
839
|
case "catch": {
|
|
812
840
|
const inner = unwrapInner(schema);
|
|
813
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
841
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth);
|
|
814
842
|
}
|
|
815
843
|
case "pipe": {
|
|
816
844
|
const inner = unwrapPipe(schema);
|
|
817
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
845
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth);
|
|
818
846
|
}
|
|
819
847
|
case "lazy": {
|
|
848
|
+
if (lazyDepth >= maxDepth) return [];
|
|
820
849
|
const inner = unwrapLazy(schema);
|
|
821
|
-
return inner === void 0 ? [] : walkSegments(inner, segments);
|
|
850
|
+
return inner === void 0 ? [] : walkSegments(inner, segments, maxDepth, lazyDepth + 1);
|
|
822
851
|
}
|
|
823
852
|
case "intersection": {
|
|
824
853
|
const left = getIntersectionLeft(schema);
|
|
825
854
|
const right = getIntersectionRight(schema);
|
|
826
|
-
const leftResults = left === void 0 ? [] : walkSegments(left, segments);
|
|
827
|
-
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);
|
|
828
857
|
return [...leftResults, ...rightResults];
|
|
829
858
|
}
|
|
830
859
|
// Leaf types — can't descend further.
|
|
@@ -845,6 +874,7 @@ function walkSegments(schema, segments) {
|
|
|
845
874
|
case "promise":
|
|
846
875
|
case "custom":
|
|
847
876
|
case "template-literal":
|
|
877
|
+
case "transform":
|
|
848
878
|
return [];
|
|
849
879
|
default: {
|
|
850
880
|
const _exhaustive = kind;
|
|
@@ -956,6 +986,7 @@ function stripRefinements(schema) {
|
|
|
956
986
|
case "promise":
|
|
957
987
|
case "custom":
|
|
958
988
|
case "template-literal":
|
|
989
|
+
case "transform":
|
|
959
990
|
return schema;
|
|
960
991
|
default: {
|
|
961
992
|
const _exhaustive = kind;
|
|
@@ -1079,6 +1110,7 @@ function stripAsyncChecks(schema) {
|
|
|
1079
1110
|
case "promise":
|
|
1080
1111
|
case "custom":
|
|
1081
1112
|
case "template-literal":
|
|
1113
|
+
case "transform":
|
|
1082
1114
|
return s;
|
|
1083
1115
|
default: {
|
|
1084
1116
|
const _exhaustive = kind;
|
|
@@ -1088,34 +1120,37 @@ function stripAsyncChecks(schema) {
|
|
|
1088
1120
|
}
|
|
1089
1121
|
return recurse(schema);
|
|
1090
1122
|
}
|
|
1091
|
-
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) {
|
|
1092
1127
|
const kind = kindOf(schema);
|
|
1093
1128
|
switch (kind) {
|
|
1094
1129
|
case "optional": {
|
|
1095
1130
|
const inner = unwrapInner(schema) ?? schema;
|
|
1096
|
-
const slimmedInner =
|
|
1131
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1097
1132
|
return stripConfig.stripOptional === true ? slimmedInner : slimmedInner.optional();
|
|
1098
1133
|
}
|
|
1099
1134
|
case "nullable": {
|
|
1100
1135
|
const inner = unwrapInner(schema) ?? schema;
|
|
1101
|
-
const slimmedInner =
|
|
1136
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1102
1137
|
return stripConfig.stripNullable === true ? slimmedInner : slimmedInner.nullable();
|
|
1103
1138
|
}
|
|
1104
1139
|
case "default": {
|
|
1105
1140
|
const inner = unwrapInner(schema) ?? schema;
|
|
1106
|
-
const slimmedInner =
|
|
1141
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1107
1142
|
if (stripConfig.stripDefaultValues === true) return slimmedInner;
|
|
1108
1143
|
const defaultValue = getDefaultValue(schema);
|
|
1109
1144
|
return slimmedInner.default(defaultValue);
|
|
1110
1145
|
}
|
|
1111
1146
|
case "readonly": {
|
|
1112
1147
|
const inner = unwrapInner(schema);
|
|
1113
|
-
return inner === void 0 ? schema :
|
|
1148
|
+
return inner === void 0 ? schema : walkSlim(inner, stripConfig, maxDepth, lazyDepth).readonly();
|
|
1114
1149
|
}
|
|
1115
1150
|
case "pipe": {
|
|
1116
1151
|
if (stripConfig.stripPipe === true) {
|
|
1117
1152
|
const inner = unwrapPipe(schema) ?? schema;
|
|
1118
|
-
return
|
|
1153
|
+
return walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1119
1154
|
}
|
|
1120
1155
|
return schema;
|
|
1121
1156
|
}
|
|
@@ -1123,20 +1158,30 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1123
1158
|
const shape = getObjectShape(schema);
|
|
1124
1159
|
const next = {};
|
|
1125
1160
|
for (const [k, v] of Object.entries(shape)) {
|
|
1126
|
-
next[k] =
|
|
1161
|
+
next[k] = walkSlim(v, stripConfig, maxDepth, lazyDepth);
|
|
1127
1162
|
}
|
|
1128
1163
|
return carryChecks(zod.z.object(next), schema, stripConfig);
|
|
1129
1164
|
}
|
|
1130
1165
|
case "array": {
|
|
1131
1166
|
const element = getArrayElement(schema);
|
|
1132
|
-
return carryChecks(
|
|
1167
|
+
return carryChecks(
|
|
1168
|
+
zod.z.array(walkSlim(element, stripConfig, maxDepth, lazyDepth)),
|
|
1169
|
+
schema,
|
|
1170
|
+
stripConfig
|
|
1171
|
+
);
|
|
1133
1172
|
}
|
|
1134
1173
|
case "set": {
|
|
1135
1174
|
const valueType = getSetValueType(schema);
|
|
1136
|
-
return carryChecks(
|
|
1175
|
+
return carryChecks(
|
|
1176
|
+
zod.z.set(walkSlim(valueType, stripConfig, maxDepth, lazyDepth)),
|
|
1177
|
+
schema,
|
|
1178
|
+
stripConfig
|
|
1179
|
+
);
|
|
1137
1180
|
}
|
|
1138
1181
|
case "tuple": {
|
|
1139
|
-
const items = getTupleItems(schema).map(
|
|
1182
|
+
const items = getTupleItems(schema).map(
|
|
1183
|
+
(it) => walkSlim(it, stripConfig, maxDepth, lazyDepth)
|
|
1184
|
+
);
|
|
1140
1185
|
const rebuilt = zod.z.tuple(
|
|
1141
1186
|
items
|
|
1142
1187
|
);
|
|
@@ -1144,18 +1189,20 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1144
1189
|
}
|
|
1145
1190
|
case "record": {
|
|
1146
1191
|
const keyType = getRecordKeyType(schema);
|
|
1147
|
-
const valueType =
|
|
1192
|
+
const valueType = walkSlim(getRecordValueType(schema), stripConfig, maxDepth, lazyDepth);
|
|
1148
1193
|
const rebuilt = zod.z.record(keyType, valueType);
|
|
1149
1194
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1150
1195
|
}
|
|
1151
1196
|
case "union": {
|
|
1152
|
-
const options = getUnionOptions(schema).map(
|
|
1197
|
+
const options = getUnionOptions(schema).map(
|
|
1198
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1199
|
+
);
|
|
1153
1200
|
const rebuilt = zod.z.union(options);
|
|
1154
1201
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1155
1202
|
}
|
|
1156
1203
|
case "discriminated-union": {
|
|
1157
1204
|
const options = getDiscriminatedOptions(schema).map(
|
|
1158
|
-
(opt) =>
|
|
1205
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1159
1206
|
);
|
|
1160
1207
|
const discriminator = getDiscriminator(schema);
|
|
1161
1208
|
if (discriminator === void 0) return schema;
|
|
@@ -1185,23 +1232,29 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1185
1232
|
case "template-literal":
|
|
1186
1233
|
return schema;
|
|
1187
1234
|
case "lazy": {
|
|
1235
|
+
if (lazyDepth >= maxDepth) return schema;
|
|
1188
1236
|
const inner = unwrapLazy(schema);
|
|
1189
1237
|
if (inner === void 0) return schema;
|
|
1190
|
-
const slimmedInner =
|
|
1238
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth + 1);
|
|
1191
1239
|
return zod.z.lazy(() => slimmedInner);
|
|
1192
1240
|
}
|
|
1193
1241
|
case "intersection": {
|
|
1194
1242
|
const left = getIntersectionLeft(schema);
|
|
1195
1243
|
const right = getIntersectionRight(schema);
|
|
1196
1244
|
if (left === void 0 || right === void 0) return schema;
|
|
1197
|
-
return zod.z.intersection(
|
|
1245
|
+
return zod.z.intersection(
|
|
1246
|
+
walkSlim(left, stripConfig, maxDepth, lazyDepth),
|
|
1247
|
+
walkSlim(right, stripConfig, maxDepth, lazyDepth)
|
|
1248
|
+
);
|
|
1198
1249
|
}
|
|
1199
1250
|
case "catch": {
|
|
1200
1251
|
const inner = unwrapInner(schema);
|
|
1201
1252
|
if (inner === void 0) return schema;
|
|
1202
|
-
const slimmedInner =
|
|
1253
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1203
1254
|
return slimmedInner.catch(getCatchDefault(schema));
|
|
1204
1255
|
}
|
|
1256
|
+
case "transform":
|
|
1257
|
+
return schema;
|
|
1205
1258
|
default: {
|
|
1206
1259
|
const _exhaustive = kind;
|
|
1207
1260
|
throw new Error(`getSlimSchema: unhandled ZodKind '${_exhaustive}'`);
|
|
@@ -1209,23 +1262,23 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1209
1262
|
}
|
|
1210
1263
|
}
|
|
1211
1264
|
|
|
1212
|
-
function deriveDefault(schema, useDefault) {
|
|
1213
|
-
return defaultForKind(kindOf(schema), schema, useDefault);
|
|
1265
|
+
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
1266
|
+
return defaultForKind(kindOf(schema), schema, useDefault, maxRecursionDepth, 0);
|
|
1214
1267
|
}
|
|
1215
|
-
function defaultForKind(kind, schema, useDefault) {
|
|
1268
|
+
function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
1216
1269
|
switch (kind) {
|
|
1217
1270
|
case "object": {
|
|
1218
1271
|
const shape = getObjectShape(schema);
|
|
1219
1272
|
const out = {};
|
|
1220
1273
|
for (const [key, subSchema] of Object.entries(shape)) {
|
|
1221
|
-
out[key] =
|
|
1274
|
+
out[key] = defaultForKind(kindOf(subSchema), subSchema, useDefault, maxDepth, lazyDepth);
|
|
1222
1275
|
}
|
|
1223
1276
|
return out;
|
|
1224
1277
|
}
|
|
1225
1278
|
case "default": {
|
|
1226
1279
|
if (useDefault) return getDefaultValue(schema);
|
|
1227
1280
|
const inner = unwrapInner(schema);
|
|
1228
|
-
return inner === void 0 ? void 0 :
|
|
1281
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1229
1282
|
}
|
|
1230
1283
|
case "optional":
|
|
1231
1284
|
return void 0;
|
|
@@ -1233,11 +1286,11 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1233
1286
|
return null;
|
|
1234
1287
|
case "readonly": {
|
|
1235
1288
|
const inner = unwrapInner(schema);
|
|
1236
|
-
return inner === void 0 ? void 0 :
|
|
1289
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1237
1290
|
}
|
|
1238
1291
|
case "pipe": {
|
|
1239
1292
|
const inner = unwrapPipe(schema);
|
|
1240
|
-
return inner === void 0 ? void 0 :
|
|
1293
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1241
1294
|
}
|
|
1242
1295
|
case "array":
|
|
1243
1296
|
return [];
|
|
@@ -1247,16 +1300,18 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1247
1300
|
return {};
|
|
1248
1301
|
case "tuple": {
|
|
1249
1302
|
const items = getTupleItems(schema);
|
|
1250
|
-
return items.map(
|
|
1303
|
+
return items.map(
|
|
1304
|
+
(item) => defaultForKind(kindOf(item), item, useDefault, maxDepth, lazyDepth)
|
|
1305
|
+
);
|
|
1251
1306
|
}
|
|
1252
1307
|
case "union": {
|
|
1253
1308
|
const options = getUnionOptions(schema);
|
|
1254
1309
|
const first = options[0];
|
|
1255
|
-
return first === void 0 ? void 0 :
|
|
1310
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1256
1311
|
}
|
|
1257
1312
|
case "discriminated-union": {
|
|
1258
1313
|
const first = getDiscriminatedUnionFirstOption(schema);
|
|
1259
|
-
return first === void 0 ? void 0 :
|
|
1314
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1260
1315
|
}
|
|
1261
1316
|
case "string":
|
|
1262
1317
|
return "";
|
|
@@ -1283,20 +1338,21 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1283
1338
|
case "nan":
|
|
1284
1339
|
return NaN;
|
|
1285
1340
|
case "lazy": {
|
|
1341
|
+
if (lazyDepth >= maxDepth) return void 0;
|
|
1286
1342
|
const inner = unwrapLazy(schema);
|
|
1287
|
-
return inner === void 0 ? void 0 :
|
|
1343
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth + 1);
|
|
1288
1344
|
}
|
|
1289
1345
|
case "intersection": {
|
|
1290
1346
|
const left = getIntersectionLeft(schema);
|
|
1291
1347
|
const right = getIntersectionRight(schema);
|
|
1292
|
-
const l = left === void 0 ? void 0 :
|
|
1293
|
-
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);
|
|
1294
1350
|
return mergeDeep(l, r);
|
|
1295
1351
|
}
|
|
1296
1352
|
case "catch": {
|
|
1297
1353
|
if (useDefault) return getCatchDefault(schema);
|
|
1298
1354
|
const inner = unwrapInner(schema);
|
|
1299
|
-
return inner === void 0 ? void 0 :
|
|
1355
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1300
1356
|
}
|
|
1301
1357
|
case "any":
|
|
1302
1358
|
case "unknown":
|
|
@@ -1305,6 +1361,7 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1305
1361
|
case "promise":
|
|
1306
1362
|
case "custom":
|
|
1307
1363
|
case "template-literal":
|
|
1364
|
+
case "transform":
|
|
1308
1365
|
return void 0;
|
|
1309
1366
|
default: {
|
|
1310
1367
|
const _exhaustive = kind;
|
|
@@ -1329,14 +1386,18 @@ function mergeDeep(base, override) {
|
|
|
1329
1386
|
return result;
|
|
1330
1387
|
}
|
|
1331
1388
|
function getDefaultValuesFromZodSchema(opts) {
|
|
1332
|
-
const { schema, useDefaultSchemaValues, constraints } = opts;
|
|
1333
|
-
const initial = deriveDefault(schema, useDefaultSchemaValues);
|
|
1389
|
+
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
1390
|
+
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
1334
1391
|
const merged = mergeDeep(initial, constraints);
|
|
1335
|
-
const slimSchema = getSlimSchema(
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1392
|
+
const slimSchema = getSlimSchema(
|
|
1393
|
+
schema,
|
|
1394
|
+
{
|
|
1395
|
+
stripDefaultValues: true,
|
|
1396
|
+
stripPipe: true,
|
|
1397
|
+
stripRefinements: true
|
|
1398
|
+
},
|
|
1399
|
+
maxRecursionDepth
|
|
1400
|
+
);
|
|
1340
1401
|
const firstParse = slimSchema.safeParse(merged);
|
|
1341
1402
|
if (firstParse.success) {
|
|
1342
1403
|
return { data: firstParse.data, success: true, slimSchema };
|
|
@@ -1344,16 +1405,16 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1344
1405
|
let fixedData = merged;
|
|
1345
1406
|
for (const issue of firstParse.error.issues) {
|
|
1346
1407
|
const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
|
|
1347
|
-
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments);
|
|
1408
|
+
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments, maxRecursionDepth);
|
|
1348
1409
|
if (candidates.length === 0) continue;
|
|
1349
1410
|
const candidate = candidates[0];
|
|
1350
1411
|
if (candidate === void 0) continue;
|
|
1351
1412
|
const valueAtPath = useFormContext.getAtPath(merged, pathSegments);
|
|
1352
|
-
const slimKinds = slimPrimitivesOf(candidate);
|
|
1413
|
+
const slimKinds = slimPrimitivesOf(candidate, maxRecursionDepth);
|
|
1353
1414
|
if (slimKinds.size > 0 && slimKinds.has(useFormContext.slimKindOf(valueAtPath))) {
|
|
1354
1415
|
continue;
|
|
1355
1416
|
}
|
|
1356
|
-
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues);
|
|
1417
|
+
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1357
1418
|
if (fixValue === SKIP) continue;
|
|
1358
1419
|
fixedData = pathSegments.length === 0 ? fixValue : useFormContext.setAtPath(fixedData, pathSegments, fixValue);
|
|
1359
1420
|
}
|
|
@@ -1364,21 +1425,22 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1364
1425
|
return { data: fixedData, success: false, slimSchema };
|
|
1365
1426
|
}
|
|
1366
1427
|
const SKIP = Symbol("atta:skip-fix");
|
|
1367
|
-
function defaultFromIssue(issue, candidate, useDefaultSchemaValues) {
|
|
1428
|
+
function defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth) {
|
|
1368
1429
|
if (issue.code === "invalid_type") {
|
|
1369
1430
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
1370
1431
|
if (du !== void 0) {
|
|
1371
1432
|
const first = getDiscriminatedUnionFirstOption(du);
|
|
1372
|
-
if (first !== void 0)
|
|
1433
|
+
if (first !== void 0)
|
|
1434
|
+
return deriveDefault(first, useDefaultSchemaValues, maxRecursionDepth);
|
|
1373
1435
|
}
|
|
1374
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1436
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1375
1437
|
}
|
|
1376
1438
|
if (issue.code === "invalid_value") {
|
|
1377
1439
|
const values = issue.values;
|
|
1378
1440
|
if (values !== void 0 && values.length > 0) return values[0];
|
|
1379
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1441
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1380
1442
|
}
|
|
1381
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1443
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1382
1444
|
}
|
|
1383
1445
|
|
|
1384
1446
|
const PATH_SEPARATOR = ".";
|
|
@@ -1468,7 +1530,8 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
1468
1530
|
function zodV4Adapter(rootSchema) {
|
|
1469
1531
|
assertZodVersion(rootSchema);
|
|
1470
1532
|
assertSupportedKinds(rootSchema);
|
|
1471
|
-
return (formKey) => {
|
|
1533
|
+
return (formKey, options) => {
|
|
1534
|
+
const maxRecursionDepth = options.maxRecursionDepth;
|
|
1472
1535
|
const leafCache = /* @__PURE__ */ new Map();
|
|
1473
1536
|
let asyncValidationFlag = null;
|
|
1474
1537
|
return {
|
|
@@ -1481,13 +1544,16 @@ function zodV4Adapter(rootSchema) {
|
|
|
1481
1544
|
const { data } = getDefaultValuesFromZodSchema({
|
|
1482
1545
|
schema: rootSchema,
|
|
1483
1546
|
useDefaultSchemaValues: config.useDefaultSchemaValues,
|
|
1484
|
-
constraints: config.constraints
|
|
1547
|
+
constraints: config.constraints,
|
|
1548
|
+
maxRecursionDepth
|
|
1485
1549
|
});
|
|
1486
1550
|
if (config.strict !== false) {
|
|
1487
1551
|
try {
|
|
1488
|
-
const strictResult = rootSchema.safeParse(
|
|
1552
|
+
const strictResult = rootSchema.safeParse(
|
|
1553
|
+
data
|
|
1554
|
+
);
|
|
1489
1555
|
if (strictResult.success) {
|
|
1490
|
-
return { data
|
|
1556
|
+
return { data, errors: void 0, success: true, formKey };
|
|
1491
1557
|
}
|
|
1492
1558
|
return {
|
|
1493
1559
|
data,
|
|
@@ -1515,15 +1581,46 @@ function zodV4Adapter(rootSchema) {
|
|
|
1515
1581
|
}
|
|
1516
1582
|
return { data, errors: void 0, success: true, formKey };
|
|
1517
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
|
+
},
|
|
1518
1615
|
getDefaultAtPath(path) {
|
|
1519
|
-
if (path.length === 0) return deriveDefault(rootSchema, true);
|
|
1520
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1616
|
+
if (path.length === 0) return deriveDefault(rootSchema, true, maxRecursionDepth);
|
|
1617
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1521
1618
|
if (first === void 0) return void 0;
|
|
1522
|
-
return deriveDefault(unwrapStructuralWrappers(first), true);
|
|
1619
|
+
return deriveDefault(unwrapStructuralWrappers(first), true, maxRecursionDepth);
|
|
1523
1620
|
},
|
|
1524
1621
|
arrayShapeAtPath(path) {
|
|
1525
1622
|
if (path.length === 0) return void 0;
|
|
1526
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1623
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1527
1624
|
if (first === void 0) return void 0;
|
|
1528
1625
|
const peeled = peelAllWrappers(first);
|
|
1529
1626
|
const kind = kindOf(peeled);
|
|
@@ -1532,13 +1629,13 @@ function zodV4Adapter(rootSchema) {
|
|
|
1532
1629
|
return void 0;
|
|
1533
1630
|
},
|
|
1534
1631
|
getSchemasAtPath(path) {
|
|
1535
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1632
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1536
1633
|
return resolved.map(
|
|
1537
1634
|
(schema) => ({
|
|
1538
1635
|
fingerprint: () => fingerprintZodSchema(schema),
|
|
1539
1636
|
needsAsyncValidation: () => containsAsyncRefine(schema),
|
|
1540
1637
|
getDefaultValues: () => ({
|
|
1541
|
-
data: deriveDefault(schema, true),
|
|
1638
|
+
data: deriveDefault(schema, true, maxRecursionDepth),
|
|
1542
1639
|
errors: void 0,
|
|
1543
1640
|
success: true,
|
|
1544
1641
|
formKey
|
|
@@ -1561,11 +1658,11 @@ function zodV4Adapter(rootSchema) {
|
|
|
1561
1658
|
},
|
|
1562
1659
|
getSlimPrimitiveTypesAtPath(path) {
|
|
1563
1660
|
if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
|
|
1564
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1661
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1565
1662
|
if (resolved.length === 0) return /* @__PURE__ */ new Set();
|
|
1566
1663
|
const out = /* @__PURE__ */ new Set();
|
|
1567
1664
|
for (const candidate of resolved) {
|
|
1568
|
-
for (const k of slimPrimitivesOf(candidate)) out.add(k);
|
|
1665
|
+
for (const k of slimPrimitivesOf(candidate, maxRecursionDepth)) out.add(k);
|
|
1569
1666
|
}
|
|
1570
1667
|
return out;
|
|
1571
1668
|
},
|
|
@@ -1580,15 +1677,15 @@ function zodV4Adapter(rootSchema) {
|
|
|
1580
1677
|
},
|
|
1581
1678
|
isRequiredAtPath(path) {
|
|
1582
1679
|
if (path.length === 0) return true;
|
|
1583
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1680
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1584
1681
|
if (resolved.length === 0) return false;
|
|
1585
1682
|
return resolved.every((candidate) => isLeafRequired(candidate));
|
|
1586
1683
|
},
|
|
1587
1684
|
getFieldMetaAtPath(path) {
|
|
1588
|
-
return resolveFieldMetaAtPath(rootSchema, path);
|
|
1685
|
+
return resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth);
|
|
1589
1686
|
},
|
|
1590
1687
|
getUnionDiscriminatorAtPath(path) {
|
|
1591
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1688
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1592
1689
|
let matchedUnion;
|
|
1593
1690
|
for (const candidate of candidates) {
|
|
1594
1691
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
@@ -1599,24 +1696,35 @@ function zodV4Adapter(rootSchema) {
|
|
|
1599
1696
|
if (matchedUnion === void 0) return void 0;
|
|
1600
1697
|
const discKey = getDiscriminator(matchedUnion);
|
|
1601
1698
|
if (discKey === void 0) return void 0;
|
|
1602
|
-
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
|
+
}
|
|
1603
1708
|
return {
|
|
1604
1709
|
discriminatorKey: discKey,
|
|
1605
1710
|
getVariantDefault(value) {
|
|
1606
|
-
for (const opt of
|
|
1711
|
+
for (const opt of options2) {
|
|
1607
1712
|
const shape = getObjectShape(opt);
|
|
1608
1713
|
const litSchema = shape[discKey];
|
|
1609
1714
|
if (litSchema === void 0) continue;
|
|
1610
1715
|
if (kindOf(litSchema) !== "literal") continue;
|
|
1611
1716
|
const literalValues = getLiteralValues(litSchema);
|
|
1612
|
-
if (literalValues.includes(value)) return deriveDefault(opt, true);
|
|
1717
|
+
if (literalValues.includes(value)) return deriveDefault(opt, true, maxRecursionDepth);
|
|
1613
1718
|
}
|
|
1614
1719
|
return void 0;
|
|
1720
|
+
},
|
|
1721
|
+
isVariantSelected(value) {
|
|
1722
|
+
return literalSet.has(value);
|
|
1615
1723
|
}
|
|
1616
1724
|
};
|
|
1617
1725
|
},
|
|
1618
|
-
validateAtPath(data, path,
|
|
1619
|
-
const trySync =
|
|
1726
|
+
validateAtPath(data, path, options2) {
|
|
1727
|
+
const trySync = options2?.sync === true;
|
|
1620
1728
|
if (trySync) {
|
|
1621
1729
|
try {
|
|
1622
1730
|
return runSync();
|
|
@@ -1634,13 +1742,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1634
1742
|
formKey
|
|
1635
1743
|
};
|
|
1636
1744
|
}
|
|
1637
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1745
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1638
1746
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1639
1747
|
const aggregated = [];
|
|
1640
1748
|
for (const candidate of resolved) {
|
|
1641
1749
|
const result = candidate.safeParse(data);
|
|
1642
1750
|
if (result.success) {
|
|
1643
|
-
return {
|
|
1751
|
+
return {
|
|
1752
|
+
data: result.data,
|
|
1753
|
+
errors: void 0,
|
|
1754
|
+
success: true,
|
|
1755
|
+
formKey
|
|
1756
|
+
};
|
|
1644
1757
|
}
|
|
1645
1758
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1646
1759
|
}
|
|
@@ -1648,7 +1761,9 @@ function zodV4Adapter(rootSchema) {
|
|
|
1648
1761
|
}
|
|
1649
1762
|
async function runAsync() {
|
|
1650
1763
|
if (path === void 0) {
|
|
1651
|
-
const result = await rootSchema.safeParseAsync(
|
|
1764
|
+
const result = await rootSchema.safeParseAsync(
|
|
1765
|
+
data
|
|
1766
|
+
);
|
|
1652
1767
|
return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
|
|
1653
1768
|
data: void 0,
|
|
1654
1769
|
errors: zodIssuesToValidationErrors(result.error.issues, formKey),
|
|
@@ -1656,13 +1771,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1656
1771
|
formKey
|
|
1657
1772
|
};
|
|
1658
1773
|
}
|
|
1659
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1774
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1660
1775
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1661
1776
|
const aggregated = [];
|
|
1662
1777
|
for (const candidate of resolved) {
|
|
1663
1778
|
const result = await candidate.safeParseAsync(data);
|
|
1664
1779
|
if (result.success) {
|
|
1665
|
-
return {
|
|
1780
|
+
return {
|
|
1781
|
+
data: result.data,
|
|
1782
|
+
errors: void 0,
|
|
1783
|
+
success: true,
|
|
1784
|
+
formKey
|
|
1785
|
+
};
|
|
1666
1786
|
}
|
|
1667
1787
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1668
1788
|
}
|
|
@@ -1840,6 +1960,7 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress)
|
|
|
1840
1960
|
case "promise":
|
|
1841
1961
|
case "custom":
|
|
1842
1962
|
case "template-literal":
|
|
1963
|
+
case "transform":
|
|
1843
1964
|
return;
|
|
1844
1965
|
}
|
|
1845
1966
|
} finally {
|
|
@@ -1854,9 +1975,9 @@ function consumePayload(schema, counters) {
|
|
|
1854
1975
|
counters.set(schema, idx + 1);
|
|
1855
1976
|
return payload;
|
|
1856
1977
|
}
|
|
1857
|
-
function resolveFieldMetaAtPath(rootSchema, path) {
|
|
1978
|
+
function resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth) {
|
|
1858
1979
|
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1859
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1980
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1860
1981
|
const target = candidates[0];
|
|
1861
1982
|
if (target === void 0) {
|
|
1862
1983
|
return {
|
|
@@ -1890,9 +2011,7 @@ function useForm(configuration) {
|
|
|
1890
2011
|
if (candidate === void 0 || candidate === null || candidate.schema === void 0) {
|
|
1891
2012
|
throw new plugin.InvalidUseFormConfigError();
|
|
1892
2013
|
}
|
|
1893
|
-
const adapter = zodV4Adapter(
|
|
1894
|
-
configuration.schema
|
|
1895
|
-
);
|
|
2014
|
+
const adapter = zodV4Adapter(configuration.schema);
|
|
1896
2015
|
return useFormContext.useAbstractForm({
|
|
1897
2016
|
...configuration,
|
|
1898
2017
|
schema: adapter
|
|
@@ -1906,4 +2025,4 @@ exports.kindOf = kindOf;
|
|
|
1906
2025
|
exports.useForm = useForm;
|
|
1907
2026
|
exports.withMeta = withMeta;
|
|
1908
2027
|
exports.zodV4Adapter = zodV4Adapter;
|
|
1909
|
-
//# sourceMappingURL=attaform.
|
|
2028
|
+
//# sourceMappingURL=attaform.C6_zOf8x.cjs.map
|