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,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.BT55rDNN.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,37 @@ 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
1150
|
const inner = unwrapPipe(schema) ?? schema;
|
|
1120
|
-
return
|
|
1151
|
+
return walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1121
1152
|
}
|
|
1122
1153
|
return schema;
|
|
1123
1154
|
}
|
|
@@ -1125,20 +1156,30 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1125
1156
|
const shape = getObjectShape(schema);
|
|
1126
1157
|
const next = {};
|
|
1127
1158
|
for (const [k, v] of Object.entries(shape)) {
|
|
1128
|
-
next[k] =
|
|
1159
|
+
next[k] = walkSlim(v, stripConfig, maxDepth, lazyDepth);
|
|
1129
1160
|
}
|
|
1130
1161
|
return carryChecks(z.object(next), schema, stripConfig);
|
|
1131
1162
|
}
|
|
1132
1163
|
case "array": {
|
|
1133
1164
|
const element = getArrayElement(schema);
|
|
1134
|
-
return carryChecks(
|
|
1165
|
+
return carryChecks(
|
|
1166
|
+
z.array(walkSlim(element, stripConfig, maxDepth, lazyDepth)),
|
|
1167
|
+
schema,
|
|
1168
|
+
stripConfig
|
|
1169
|
+
);
|
|
1135
1170
|
}
|
|
1136
1171
|
case "set": {
|
|
1137
1172
|
const valueType = getSetValueType(schema);
|
|
1138
|
-
return carryChecks(
|
|
1173
|
+
return carryChecks(
|
|
1174
|
+
z.set(walkSlim(valueType, stripConfig, maxDepth, lazyDepth)),
|
|
1175
|
+
schema,
|
|
1176
|
+
stripConfig
|
|
1177
|
+
);
|
|
1139
1178
|
}
|
|
1140
1179
|
case "tuple": {
|
|
1141
|
-
const items = getTupleItems(schema).map(
|
|
1180
|
+
const items = getTupleItems(schema).map(
|
|
1181
|
+
(it) => walkSlim(it, stripConfig, maxDepth, lazyDepth)
|
|
1182
|
+
);
|
|
1142
1183
|
const rebuilt = z.tuple(
|
|
1143
1184
|
items
|
|
1144
1185
|
);
|
|
@@ -1146,18 +1187,20 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1146
1187
|
}
|
|
1147
1188
|
case "record": {
|
|
1148
1189
|
const keyType = getRecordKeyType(schema);
|
|
1149
|
-
const valueType =
|
|
1190
|
+
const valueType = walkSlim(getRecordValueType(schema), stripConfig, maxDepth, lazyDepth);
|
|
1150
1191
|
const rebuilt = z.record(keyType, valueType);
|
|
1151
1192
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1152
1193
|
}
|
|
1153
1194
|
case "union": {
|
|
1154
|
-
const options = getUnionOptions(schema).map(
|
|
1195
|
+
const options = getUnionOptions(schema).map(
|
|
1196
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1197
|
+
);
|
|
1155
1198
|
const rebuilt = z.union(options);
|
|
1156
1199
|
return carryChecks(rebuilt, schema, stripConfig);
|
|
1157
1200
|
}
|
|
1158
1201
|
case "discriminated-union": {
|
|
1159
1202
|
const options = getDiscriminatedOptions(schema).map(
|
|
1160
|
-
(opt) =>
|
|
1203
|
+
(opt) => walkSlim(opt, stripConfig, maxDepth, lazyDepth)
|
|
1161
1204
|
);
|
|
1162
1205
|
const discriminator = getDiscriminator(schema);
|
|
1163
1206
|
if (discriminator === void 0) return schema;
|
|
@@ -1187,23 +1230,29 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1187
1230
|
case "template-literal":
|
|
1188
1231
|
return schema;
|
|
1189
1232
|
case "lazy": {
|
|
1233
|
+
if (lazyDepth >= maxDepth) return schema;
|
|
1190
1234
|
const inner = unwrapLazy(schema);
|
|
1191
1235
|
if (inner === void 0) return schema;
|
|
1192
|
-
const slimmedInner =
|
|
1236
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth + 1);
|
|
1193
1237
|
return z.lazy(() => slimmedInner);
|
|
1194
1238
|
}
|
|
1195
1239
|
case "intersection": {
|
|
1196
1240
|
const left = getIntersectionLeft(schema);
|
|
1197
1241
|
const right = getIntersectionRight(schema);
|
|
1198
1242
|
if (left === void 0 || right === void 0) return schema;
|
|
1199
|
-
return z.intersection(
|
|
1243
|
+
return z.intersection(
|
|
1244
|
+
walkSlim(left, stripConfig, maxDepth, lazyDepth),
|
|
1245
|
+
walkSlim(right, stripConfig, maxDepth, lazyDepth)
|
|
1246
|
+
);
|
|
1200
1247
|
}
|
|
1201
1248
|
case "catch": {
|
|
1202
1249
|
const inner = unwrapInner(schema);
|
|
1203
1250
|
if (inner === void 0) return schema;
|
|
1204
|
-
const slimmedInner =
|
|
1251
|
+
const slimmedInner = walkSlim(inner, stripConfig, maxDepth, lazyDepth);
|
|
1205
1252
|
return slimmedInner.catch(getCatchDefault(schema));
|
|
1206
1253
|
}
|
|
1254
|
+
case "transform":
|
|
1255
|
+
return schema;
|
|
1207
1256
|
default: {
|
|
1208
1257
|
const _exhaustive = kind;
|
|
1209
1258
|
throw new Error(`getSlimSchema: unhandled ZodKind '${_exhaustive}'`);
|
|
@@ -1211,23 +1260,23 @@ function getSlimSchema(schema, stripConfig) {
|
|
|
1211
1260
|
}
|
|
1212
1261
|
}
|
|
1213
1262
|
|
|
1214
|
-
function deriveDefault(schema, useDefault) {
|
|
1215
|
-
return defaultForKind(kindOf(schema), schema, useDefault);
|
|
1263
|
+
function deriveDefault(schema, useDefault, maxRecursionDepth) {
|
|
1264
|
+
return defaultForKind(kindOf(schema), schema, useDefault, maxRecursionDepth, 0);
|
|
1216
1265
|
}
|
|
1217
|
-
function defaultForKind(kind, schema, useDefault) {
|
|
1266
|
+
function defaultForKind(kind, schema, useDefault, maxDepth, lazyDepth) {
|
|
1218
1267
|
switch (kind) {
|
|
1219
1268
|
case "object": {
|
|
1220
1269
|
const shape = getObjectShape(schema);
|
|
1221
1270
|
const out = {};
|
|
1222
1271
|
for (const [key, subSchema] of Object.entries(shape)) {
|
|
1223
|
-
out[key] =
|
|
1272
|
+
out[key] = defaultForKind(kindOf(subSchema), subSchema, useDefault, maxDepth, lazyDepth);
|
|
1224
1273
|
}
|
|
1225
1274
|
return out;
|
|
1226
1275
|
}
|
|
1227
1276
|
case "default": {
|
|
1228
1277
|
if (useDefault) return getDefaultValue(schema);
|
|
1229
1278
|
const inner = unwrapInner(schema);
|
|
1230
|
-
return inner === void 0 ? void 0 :
|
|
1279
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1231
1280
|
}
|
|
1232
1281
|
case "optional":
|
|
1233
1282
|
return void 0;
|
|
@@ -1235,11 +1284,11 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1235
1284
|
return null;
|
|
1236
1285
|
case "readonly": {
|
|
1237
1286
|
const inner = unwrapInner(schema);
|
|
1238
|
-
return inner === void 0 ? void 0 :
|
|
1287
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1239
1288
|
}
|
|
1240
1289
|
case "pipe": {
|
|
1241
1290
|
const inner = unwrapPipe(schema);
|
|
1242
|
-
return inner === void 0 ? void 0 :
|
|
1291
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1243
1292
|
}
|
|
1244
1293
|
case "array":
|
|
1245
1294
|
return [];
|
|
@@ -1249,16 +1298,18 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1249
1298
|
return {};
|
|
1250
1299
|
case "tuple": {
|
|
1251
1300
|
const items = getTupleItems(schema);
|
|
1252
|
-
return items.map(
|
|
1301
|
+
return items.map(
|
|
1302
|
+
(item) => defaultForKind(kindOf(item), item, useDefault, maxDepth, lazyDepth)
|
|
1303
|
+
);
|
|
1253
1304
|
}
|
|
1254
1305
|
case "union": {
|
|
1255
1306
|
const options = getUnionOptions(schema);
|
|
1256
1307
|
const first = options[0];
|
|
1257
|
-
return first === void 0 ? void 0 :
|
|
1308
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1258
1309
|
}
|
|
1259
1310
|
case "discriminated-union": {
|
|
1260
1311
|
const first = getDiscriminatedUnionFirstOption(schema);
|
|
1261
|
-
return first === void 0 ? void 0 :
|
|
1312
|
+
return first === void 0 ? void 0 : defaultForKind(kindOf(first), first, useDefault, maxDepth, lazyDepth);
|
|
1262
1313
|
}
|
|
1263
1314
|
case "string":
|
|
1264
1315
|
return "";
|
|
@@ -1285,20 +1336,21 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1285
1336
|
case "nan":
|
|
1286
1337
|
return NaN;
|
|
1287
1338
|
case "lazy": {
|
|
1339
|
+
if (lazyDepth >= maxDepth) return void 0;
|
|
1288
1340
|
const inner = unwrapLazy(schema);
|
|
1289
|
-
return inner === void 0 ? void 0 :
|
|
1341
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth + 1);
|
|
1290
1342
|
}
|
|
1291
1343
|
case "intersection": {
|
|
1292
1344
|
const left = getIntersectionLeft(schema);
|
|
1293
1345
|
const right = getIntersectionRight(schema);
|
|
1294
|
-
const l = left === void 0 ? void 0 :
|
|
1295
|
-
const r = right === void 0 ? void 0 :
|
|
1346
|
+
const l = left === void 0 ? void 0 : defaultForKind(kindOf(left), left, useDefault, maxDepth, lazyDepth);
|
|
1347
|
+
const r = right === void 0 ? void 0 : defaultForKind(kindOf(right), right, useDefault, maxDepth, lazyDepth);
|
|
1296
1348
|
return mergeDeep(l, r);
|
|
1297
1349
|
}
|
|
1298
1350
|
case "catch": {
|
|
1299
1351
|
if (useDefault) return getCatchDefault(schema);
|
|
1300
1352
|
const inner = unwrapInner(schema);
|
|
1301
|
-
return inner === void 0 ? void 0 :
|
|
1353
|
+
return inner === void 0 ? void 0 : defaultForKind(kindOf(inner), inner, useDefault, maxDepth, lazyDepth);
|
|
1302
1354
|
}
|
|
1303
1355
|
case "any":
|
|
1304
1356
|
case "unknown":
|
|
@@ -1307,6 +1359,7 @@ function defaultForKind(kind, schema, useDefault) {
|
|
|
1307
1359
|
case "promise":
|
|
1308
1360
|
case "custom":
|
|
1309
1361
|
case "template-literal":
|
|
1362
|
+
case "transform":
|
|
1310
1363
|
return void 0;
|
|
1311
1364
|
default: {
|
|
1312
1365
|
const _exhaustive = kind;
|
|
@@ -1331,14 +1384,18 @@ function mergeDeep(base, override) {
|
|
|
1331
1384
|
return result;
|
|
1332
1385
|
}
|
|
1333
1386
|
function getDefaultValuesFromZodSchema(opts) {
|
|
1334
|
-
const { schema, useDefaultSchemaValues, constraints } = opts;
|
|
1335
|
-
const initial = deriveDefault(schema, useDefaultSchemaValues);
|
|
1387
|
+
const { schema, useDefaultSchemaValues, constraints, maxRecursionDepth } = opts;
|
|
1388
|
+
const initial = deriveDefault(schema, useDefaultSchemaValues, maxRecursionDepth);
|
|
1336
1389
|
const merged = mergeDeep(initial, constraints);
|
|
1337
|
-
const slimSchema = getSlimSchema(
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1390
|
+
const slimSchema = getSlimSchema(
|
|
1391
|
+
schema,
|
|
1392
|
+
{
|
|
1393
|
+
stripDefaultValues: true,
|
|
1394
|
+
stripPipe: true,
|
|
1395
|
+
stripRefinements: true
|
|
1396
|
+
},
|
|
1397
|
+
maxRecursionDepth
|
|
1398
|
+
);
|
|
1342
1399
|
const firstParse = slimSchema.safeParse(merged);
|
|
1343
1400
|
if (firstParse.success) {
|
|
1344
1401
|
return { data: firstParse.data, success: true, slimSchema };
|
|
@@ -1346,16 +1403,16 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1346
1403
|
let fixedData = merged;
|
|
1347
1404
|
for (const issue of firstParse.error.issues) {
|
|
1348
1405
|
const pathSegments = issue.path.map((seg) => typeof seg === "number" ? seg : String(seg));
|
|
1349
|
-
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments);
|
|
1406
|
+
const candidates = getNestedZodSchemasAtPath(slimSchema, pathSegments, maxRecursionDepth);
|
|
1350
1407
|
if (candidates.length === 0) continue;
|
|
1351
1408
|
const candidate = candidates[0];
|
|
1352
1409
|
if (candidate === void 0) continue;
|
|
1353
1410
|
const valueAtPath = getAtPath(merged, pathSegments);
|
|
1354
|
-
const slimKinds = slimPrimitivesOf(candidate);
|
|
1411
|
+
const slimKinds = slimPrimitivesOf(candidate, maxRecursionDepth);
|
|
1355
1412
|
if (slimKinds.size > 0 && slimKinds.has(slimKindOf(valueAtPath))) {
|
|
1356
1413
|
continue;
|
|
1357
1414
|
}
|
|
1358
|
-
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues);
|
|
1415
|
+
const fixValue = defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1359
1416
|
if (fixValue === SKIP) continue;
|
|
1360
1417
|
fixedData = pathSegments.length === 0 ? fixValue : setAtPath(fixedData, pathSegments, fixValue);
|
|
1361
1418
|
}
|
|
@@ -1366,21 +1423,22 @@ function getDefaultValuesFromZodSchema(opts) {
|
|
|
1366
1423
|
return { data: fixedData, success: false, slimSchema };
|
|
1367
1424
|
}
|
|
1368
1425
|
const SKIP = Symbol("atta:skip-fix");
|
|
1369
|
-
function defaultFromIssue(issue, candidate, useDefaultSchemaValues) {
|
|
1426
|
+
function defaultFromIssue(issue, candidate, useDefaultSchemaValues, maxRecursionDepth) {
|
|
1370
1427
|
if (issue.code === "invalid_type") {
|
|
1371
1428
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
1372
1429
|
if (du !== void 0) {
|
|
1373
1430
|
const first = getDiscriminatedUnionFirstOption(du);
|
|
1374
|
-
if (first !== void 0)
|
|
1431
|
+
if (first !== void 0)
|
|
1432
|
+
return deriveDefault(first, useDefaultSchemaValues, maxRecursionDepth);
|
|
1375
1433
|
}
|
|
1376
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1434
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1377
1435
|
}
|
|
1378
1436
|
if (issue.code === "invalid_value") {
|
|
1379
1437
|
const values = issue.values;
|
|
1380
1438
|
if (values !== void 0 && values.length > 0) return values[0];
|
|
1381
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1439
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1382
1440
|
}
|
|
1383
|
-
return deriveDefault(candidate, useDefaultSchemaValues);
|
|
1441
|
+
return deriveDefault(candidate, useDefaultSchemaValues, maxRecursionDepth);
|
|
1384
1442
|
}
|
|
1385
1443
|
|
|
1386
1444
|
const PATH_SEPARATOR = ".";
|
|
@@ -1470,7 +1528,8 @@ function isLeafRequired(schema, depth = 0) {
|
|
|
1470
1528
|
function zodV4Adapter(rootSchema) {
|
|
1471
1529
|
assertZodVersion(rootSchema);
|
|
1472
1530
|
assertSupportedKinds(rootSchema);
|
|
1473
|
-
return (formKey) => {
|
|
1531
|
+
return (formKey, options) => {
|
|
1532
|
+
const maxRecursionDepth = options.maxRecursionDepth;
|
|
1474
1533
|
const leafCache = /* @__PURE__ */ new Map();
|
|
1475
1534
|
let asyncValidationFlag = null;
|
|
1476
1535
|
return {
|
|
@@ -1483,13 +1542,16 @@ function zodV4Adapter(rootSchema) {
|
|
|
1483
1542
|
const { data } = getDefaultValuesFromZodSchema({
|
|
1484
1543
|
schema: rootSchema,
|
|
1485
1544
|
useDefaultSchemaValues: config.useDefaultSchemaValues,
|
|
1486
|
-
constraints: config.constraints
|
|
1545
|
+
constraints: config.constraints,
|
|
1546
|
+
maxRecursionDepth
|
|
1487
1547
|
});
|
|
1488
1548
|
if (config.strict !== false) {
|
|
1489
1549
|
try {
|
|
1490
|
-
const strictResult = rootSchema.safeParse(
|
|
1550
|
+
const strictResult = rootSchema.safeParse(
|
|
1551
|
+
data
|
|
1552
|
+
);
|
|
1491
1553
|
if (strictResult.success) {
|
|
1492
|
-
return { data
|
|
1554
|
+
return { data, errors: void 0, success: true, formKey };
|
|
1493
1555
|
}
|
|
1494
1556
|
return {
|
|
1495
1557
|
data,
|
|
@@ -1517,15 +1579,46 @@ function zodV4Adapter(rootSchema) {
|
|
|
1517
1579
|
}
|
|
1518
1580
|
return { data, errors: void 0, success: true, formKey };
|
|
1519
1581
|
},
|
|
1582
|
+
normalizeWriteValueAtPath(value, path) {
|
|
1583
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1584
|
+
const [first] = candidates;
|
|
1585
|
+
if (first === void 0) return value;
|
|
1586
|
+
let current = first;
|
|
1587
|
+
let result = value;
|
|
1588
|
+
for (let i = 0; i < 64; i++) {
|
|
1589
|
+
if (kindOf(current) !== "pipe") break;
|
|
1590
|
+
const pipeIn = unwrapPipeIn(current);
|
|
1591
|
+
if (pipeIn === void 0 || kindOf(pipeIn) !== "transform") break;
|
|
1592
|
+
const fn = readTransformFn(pipeIn);
|
|
1593
|
+
if (typeof fn !== "function") break;
|
|
1594
|
+
let next;
|
|
1595
|
+
try {
|
|
1596
|
+
next = fn(result);
|
|
1597
|
+
} catch (cause) {
|
|
1598
|
+
throw new Error(
|
|
1599
|
+
`[attaform] input normalization at path "${path.join(".")}" threw \u2014 write rejected.`,
|
|
1600
|
+
{ cause }
|
|
1601
|
+
);
|
|
1602
|
+
}
|
|
1603
|
+
if (next instanceof Promise) {
|
|
1604
|
+
return value;
|
|
1605
|
+
}
|
|
1606
|
+
result = next;
|
|
1607
|
+
const out = unwrapPipeOut(current);
|
|
1608
|
+
if (out === void 0) break;
|
|
1609
|
+
current = out;
|
|
1610
|
+
}
|
|
1611
|
+
return result;
|
|
1612
|
+
},
|
|
1520
1613
|
getDefaultAtPath(path) {
|
|
1521
|
-
if (path.length === 0) return deriveDefault(rootSchema, true);
|
|
1522
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1614
|
+
if (path.length === 0) return deriveDefault(rootSchema, true, maxRecursionDepth);
|
|
1615
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1523
1616
|
if (first === void 0) return void 0;
|
|
1524
|
-
return deriveDefault(unwrapStructuralWrappers(first), true);
|
|
1617
|
+
return deriveDefault(unwrapStructuralWrappers(first), true, maxRecursionDepth);
|
|
1525
1618
|
},
|
|
1526
1619
|
arrayShapeAtPath(path) {
|
|
1527
1620
|
if (path.length === 0) return void 0;
|
|
1528
|
-
const [first] = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1621
|
+
const [first] = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1529
1622
|
if (first === void 0) return void 0;
|
|
1530
1623
|
const peeled = peelAllWrappers(first);
|
|
1531
1624
|
const kind = kindOf(peeled);
|
|
@@ -1534,13 +1627,13 @@ function zodV4Adapter(rootSchema) {
|
|
|
1534
1627
|
return void 0;
|
|
1535
1628
|
},
|
|
1536
1629
|
getSchemasAtPath(path) {
|
|
1537
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1630
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1538
1631
|
return resolved.map(
|
|
1539
1632
|
(schema) => ({
|
|
1540
1633
|
fingerprint: () => fingerprintZodSchema(schema),
|
|
1541
1634
|
needsAsyncValidation: () => containsAsyncRefine(schema),
|
|
1542
1635
|
getDefaultValues: () => ({
|
|
1543
|
-
data: deriveDefault(schema, true),
|
|
1636
|
+
data: deriveDefault(schema, true, maxRecursionDepth),
|
|
1544
1637
|
errors: void 0,
|
|
1545
1638
|
success: true,
|
|
1546
1639
|
formKey
|
|
@@ -1563,11 +1656,11 @@ function zodV4Adapter(rootSchema) {
|
|
|
1563
1656
|
},
|
|
1564
1657
|
getSlimPrimitiveTypesAtPath(path) {
|
|
1565
1658
|
if (path.length === 0) return /* @__PURE__ */ new Set(["object"]);
|
|
1566
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1659
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1567
1660
|
if (resolved.length === 0) return /* @__PURE__ */ new Set();
|
|
1568
1661
|
const out = /* @__PURE__ */ new Set();
|
|
1569
1662
|
for (const candidate of resolved) {
|
|
1570
|
-
for (const k of slimPrimitivesOf(candidate)) out.add(k);
|
|
1663
|
+
for (const k of slimPrimitivesOf(candidate, maxRecursionDepth)) out.add(k);
|
|
1571
1664
|
}
|
|
1572
1665
|
return out;
|
|
1573
1666
|
},
|
|
@@ -1582,15 +1675,15 @@ function zodV4Adapter(rootSchema) {
|
|
|
1582
1675
|
},
|
|
1583
1676
|
isRequiredAtPath(path) {
|
|
1584
1677
|
if (path.length === 0) return true;
|
|
1585
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1678
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1586
1679
|
if (resolved.length === 0) return false;
|
|
1587
1680
|
return resolved.every((candidate) => isLeafRequired(candidate));
|
|
1588
1681
|
},
|
|
1589
1682
|
getFieldMetaAtPath(path) {
|
|
1590
|
-
return resolveFieldMetaAtPath(rootSchema, path);
|
|
1683
|
+
return resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth);
|
|
1591
1684
|
},
|
|
1592
1685
|
getUnionDiscriminatorAtPath(path) {
|
|
1593
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1686
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1594
1687
|
let matchedUnion;
|
|
1595
1688
|
for (const candidate of candidates) {
|
|
1596
1689
|
const du = unwrapToDiscriminatedUnion(candidate);
|
|
@@ -1601,24 +1694,35 @@ function zodV4Adapter(rootSchema) {
|
|
|
1601
1694
|
if (matchedUnion === void 0) return void 0;
|
|
1602
1695
|
const discKey = getDiscriminator(matchedUnion);
|
|
1603
1696
|
if (discKey === void 0) return void 0;
|
|
1604
|
-
const
|
|
1697
|
+
const options2 = getDiscriminatedOptions(matchedUnion);
|
|
1698
|
+
const literalSet = /* @__PURE__ */ new Set();
|
|
1699
|
+
for (const opt of options2) {
|
|
1700
|
+
const shape = getObjectShape(opt);
|
|
1701
|
+
const litSchema = shape[discKey];
|
|
1702
|
+
if (litSchema === void 0) continue;
|
|
1703
|
+
if (kindOf(litSchema) !== "literal") continue;
|
|
1704
|
+
for (const v of getLiteralValues(litSchema)) literalSet.add(v);
|
|
1705
|
+
}
|
|
1605
1706
|
return {
|
|
1606
1707
|
discriminatorKey: discKey,
|
|
1607
1708
|
getVariantDefault(value) {
|
|
1608
|
-
for (const opt of
|
|
1709
|
+
for (const opt of options2) {
|
|
1609
1710
|
const shape = getObjectShape(opt);
|
|
1610
1711
|
const litSchema = shape[discKey];
|
|
1611
1712
|
if (litSchema === void 0) continue;
|
|
1612
1713
|
if (kindOf(litSchema) !== "literal") continue;
|
|
1613
1714
|
const literalValues = getLiteralValues(litSchema);
|
|
1614
|
-
if (literalValues.includes(value)) return deriveDefault(opt, true);
|
|
1715
|
+
if (literalValues.includes(value)) return deriveDefault(opt, true, maxRecursionDepth);
|
|
1615
1716
|
}
|
|
1616
1717
|
return void 0;
|
|
1718
|
+
},
|
|
1719
|
+
isVariantSelected(value) {
|
|
1720
|
+
return literalSet.has(value);
|
|
1617
1721
|
}
|
|
1618
1722
|
};
|
|
1619
1723
|
},
|
|
1620
|
-
validateAtPath(data, path,
|
|
1621
|
-
const trySync =
|
|
1724
|
+
validateAtPath(data, path, options2) {
|
|
1725
|
+
const trySync = options2?.sync === true;
|
|
1622
1726
|
if (trySync) {
|
|
1623
1727
|
try {
|
|
1624
1728
|
return runSync();
|
|
@@ -1636,13 +1740,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1636
1740
|
formKey
|
|
1637
1741
|
};
|
|
1638
1742
|
}
|
|
1639
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1743
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1640
1744
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1641
1745
|
const aggregated = [];
|
|
1642
1746
|
for (const candidate of resolved) {
|
|
1643
1747
|
const result = candidate.safeParse(data);
|
|
1644
1748
|
if (result.success) {
|
|
1645
|
-
return {
|
|
1749
|
+
return {
|
|
1750
|
+
data: result.data,
|
|
1751
|
+
errors: void 0,
|
|
1752
|
+
success: true,
|
|
1753
|
+
formKey
|
|
1754
|
+
};
|
|
1646
1755
|
}
|
|
1647
1756
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1648
1757
|
}
|
|
@@ -1650,7 +1759,9 @@ function zodV4Adapter(rootSchema) {
|
|
|
1650
1759
|
}
|
|
1651
1760
|
async function runAsync() {
|
|
1652
1761
|
if (path === void 0) {
|
|
1653
|
-
const result = await rootSchema.safeParseAsync(
|
|
1762
|
+
const result = await rootSchema.safeParseAsync(
|
|
1763
|
+
data
|
|
1764
|
+
);
|
|
1654
1765
|
return result.success ? { data: result.data, errors: void 0, success: true, formKey } : {
|
|
1655
1766
|
data: void 0,
|
|
1656
1767
|
errors: zodIssuesToValidationErrors(result.error.issues, formKey),
|
|
@@ -1658,13 +1769,18 @@ function zodV4Adapter(rootSchema) {
|
|
|
1658
1769
|
formKey
|
|
1659
1770
|
};
|
|
1660
1771
|
}
|
|
1661
|
-
const resolved = getNestedZodSchemasAtPath(rootSchema, path);
|
|
1772
|
+
const resolved = getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1662
1773
|
if (resolved.length === 0) return pathNotFound(path);
|
|
1663
1774
|
const aggregated = [];
|
|
1664
1775
|
for (const candidate of resolved) {
|
|
1665
1776
|
const result = await candidate.safeParseAsync(data);
|
|
1666
1777
|
if (result.success) {
|
|
1667
|
-
return {
|
|
1778
|
+
return {
|
|
1779
|
+
data: result.data,
|
|
1780
|
+
errors: void 0,
|
|
1781
|
+
success: true,
|
|
1782
|
+
formKey
|
|
1783
|
+
};
|
|
1668
1784
|
}
|
|
1669
1785
|
aggregated.push(...zodIssuesToValidationErrors(result.error.issues, formKey));
|
|
1670
1786
|
}
|
|
@@ -1842,6 +1958,7 @@ function walkForMeta(schema, path, map, counters, lastPathPerSchema, inProgress)
|
|
|
1842
1958
|
case "promise":
|
|
1843
1959
|
case "custom":
|
|
1844
1960
|
case "template-literal":
|
|
1961
|
+
case "transform":
|
|
1845
1962
|
return;
|
|
1846
1963
|
}
|
|
1847
1964
|
} finally {
|
|
@@ -1856,9 +1973,9 @@ function consumePayload(schema, counters) {
|
|
|
1856
1973
|
counters.set(schema, idx + 1);
|
|
1857
1974
|
return payload;
|
|
1858
1975
|
}
|
|
1859
|
-
function resolveFieldMetaAtPath(rootSchema, path) {
|
|
1976
|
+
function resolveFieldMetaAtPath(rootSchema, path, maxRecursionDepth) {
|
|
1860
1977
|
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1861
|
-
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path);
|
|
1978
|
+
const candidates = path.length === 0 ? [rootSchema] : getNestedZodSchemasAtPath(rootSchema, path, maxRecursionDepth);
|
|
1862
1979
|
const target = candidates[0];
|
|
1863
1980
|
if (target === void 0) {
|
|
1864
1981
|
return {
|
|
@@ -1892,9 +2009,7 @@ function useForm(configuration) {
|
|
|
1892
2009
|
if (candidate === void 0 || candidate === null || candidate.schema === void 0) {
|
|
1893
2010
|
throw new InvalidUseFormConfigError();
|
|
1894
2011
|
}
|
|
1895
|
-
const adapter = zodV4Adapter(
|
|
1896
|
-
configuration.schema
|
|
1897
|
-
);
|
|
2012
|
+
const adapter = zodV4Adapter(configuration.schema);
|
|
1898
2013
|
return useAbstractForm({
|
|
1899
2014
|
...configuration,
|
|
1900
2015
|
schema: adapter
|
|
@@ -1902,4 +2017,4 @@ function useForm(configuration) {
|
|
|
1902
2017
|
}
|
|
1903
2018
|
|
|
1904
2019
|
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.
|
|
2020
|
+
//# sourceMappingURL=attaform.Cj0pCNVn.mjs.map
|